'use strict'; const https = require('https'); const { IngressClient, IngressInput } = require('/home/xesar/WebstormProjects/restreamer-ui-v2/node_modules/livekit-server-sdk'); const LK_API_KEY = 'APIBTqTGxf9htMK'; const LK_API_SECRET = '0dOHWPffwneaPg7OYpe4PeAes21zLJfeYJB9cKzSTtXW'; const LK_HTTP_URL = 'https://livekit-server.nextream.sytes.net'; const CADDY_HOST = 'djmaster.nextream.sytes.net'; const sdp = [ 'v=0', 'o=- 0 0 IN IP4 127.0.0.1', 's=-', 't=0 0', 'm=video 9 UDP/TLS/RTP/SAVPF 96', 'c=IN IP4 0.0.0.0', 'a=sendonly', 'a=rtpmap:96 H264/90000', 'a=mid:0', ].join('\r\n') + '\r\n'; function post(path, extraHeaders) { return new Promise((resolve, reject) => { const req = https.request({ hostname: CADDY_HOST, path, method: 'POST', headers: { 'Content-Type': 'application/sdp', 'Content-Length': Buffer.byteLength(sdp), ...extraHeaders, }, rejectUnauthorized: false, timeout: 10000, }, (r) => { let d = ''; r.on('data', (c) => (d += c)); r.on('end', () => resolve({ status: r.statusCode, body: d.slice(0, 200) })); }); req.on('error', reject); req.on('timeout', () => { req.destroy(); reject(new Error('timeout')); }); req.write(sdp); req.end(); }); } (async () => { const client = new IngressClient(LK_HTTP_URL, LK_API_KEY, LK_API_SECRET); const ingress = await client.createIngress(IngressInput.WHIP_INPUT, { name: 'test-whip-post', roomName: 'test', participantIdentity: 'obs', participantName: 'OBS', }); console.log('stream_key :', ingress.streamKey); console.log('ingress.url:', ingress.url); console.log('\n[A] POST /w/ (stream_key in URL path)'); const a = await post('/w/' + ingress.streamKey, {}); console.log(' status:', a.status, '| body:', a.body); console.log('\n[B] POST /w (Authorization: Bearer )'); const b = await post('/w', { Authorization: 'Bearer ' + ingress.streamKey }); console.log(' status:', b.status, '| body:', b.body); await client.deleteIngress(ingress.ingressId).catch(() => {}); console.log('\nIngress eliminado'); })().catch((e) => { console.error(e.message); process.exit(1); });