Skip to content

Code Examples

Ready-to-use code examples for integrating Lunar Stream into your applications.

Language/PlatformDescription
Node.jsBackend integration with Express.js
JavaBackend integration with Spring Boot
GoBackend integration with net/http
PHPBackend integration with Laravel
PythonBackend integration with Flask/FastAPI
cURLCommand-line API examples
Web PlayerBrowser-based HLS playback
MobileReact 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-here

Basic 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:

Released under the MIT License.