Code Examples
Ready-to-use code examples for integrating Lunar Stream into your applications.
Quick Links
| Language/Platform | Description |
|---|---|
| Node.js | Backend integration with Express.js |
| Java | Backend integration with Spring Boot |
| Go | Backend integration with net/http |
| PHP | Backend integration with Laravel |
| Python | Backend integration with Flask/FastAPI |
| cURL | Command-line API examples |
| Web Player | Browser-based HLS playback |
| Mobile | React Native & native SDK examples |
Environment Setup
All examples use these environment variables:
bash
# .env
LUNAR_STREAM_API_URL=https://api.lunarstream.kozow.com/api/v1
LUNAR_STREAM_API_KEY=ls_proj_v1_your_api_key_here
LUNAR_STREAM_PROJECT_ID=your-project-id-hereBasic Integration Flow
javascript
// 1. Get available media servers
const servers = await lunarStream.getMediaServers();
// 2. Create a livestream
const stream = await lunarStream.createLivestream({
name: 'My Stream',
mediaServerId: servers[0].id
});
// 3. Give broadcaster the RTMP URL
const rtmpUrl = `${stream.rmtpServer}/${stream.streamKeyWithParams}`;
// 4. Give viewers the HLS URL
const hlsUrl = stream.hlsSources[0].url;Download Examples
All examples are available on GitHub: