NorskDuplex.webRtcBrowser() method

Playback audio/video via webrtc to a browser, and accept audio/video input from a browser. The browser client must conform to a custom protocol as implemented in the hosted test page. (Available from WebRTCBrowserNode.playerUrl For general WebRTC ingest prefer the WHIP input node, and for egest to a downstream media server use the WHIP output node.

Signature:

webRtcBrowser(settings: WebRTCBrowserSettings): Promise<WebRTCBrowserNode>;

Parameters

Parameter Type Description

settings

WebRTCBrowserSettings

Options for the webrtc node

Returns:

Example [01_rtmp_to_webrtc.ts]

Subscribe to an RTMP source and generate local WebRTC output from it

let input = await norsk.input.rtmpServer({ id: "rtmpInput", port: 5001 }); 
let output = await norsk.duplex.webRtcBrowser({ id: "webrtc" }); 

output.subscribe([{ source: input, sourceSelector: selectAV }]); 
console.log(`Local player: ${output.playerUrl}`);

Run the following command to generate example input at url rtmp://127.0.0.1:5001/norsk/high:

ffmpeg -v error -re -f lavfi -i "sine=frequency=220:sample_rate=48000" -loop 1 -i data/test-src-still.png -vf drawtext=fontfile=Arial.ttf:text="%{frame_num}":start_number=1:x=980:y=330:fontcolor=black:fontsize=40:box=1:boxcolor=white:boxborderw=5,scale=1280:720 -vcodec h264 -b:v 150000 -b:a 20000 -aspect 1280:720 -x264opts "keyint=25:min-keyint=25:no-scenecut:bframes=0" -bluray-compat true -tune stillimage -preset fast -pix_fmt yuv420p -acodec aac -metadata language=en -f flv 'rtmp://127.0.0.1:5001/norsk/high'

Example [02_srt_to_webrtc.ts]

Subscribe to an SRT source and generate local WebRTC output from it

export async function main() {
  const norsk = await Norsk.connect();

  let input = await norsk.input.srt(srtInputSettings);
  let output = await norsk.duplex.webRtcBrowser({ id: "webrtc" })

  output.subscribe([{ source: input, sourceSelector: selectAV }]);
  console.log(`Local player: ${output.playerUrl}`);
}

const srtInputSettings: SrtInputSettings = {
  id: "srtInput",
  ip: "127.0.0.1",
  port: 5001,
  mode: "listener",
  sourceName: "camera1",
};

Run the following command to generate example input at url srt://127.0.0.1:5001:

ffmpeg -v error -re -f lavfi -i "sine=frequency=220:sample_rate=48000" -loop 1 -i data/test-src-still.png -vf drawtext=fontfile=Arial.ttf:text="%{frame_num}":start_number=1:x=980:y=330:fontcolor=black:fontsize=40:box=1:boxcolor=white:boxborderw=5,scale=1280:720 -vcodec h264 -b:v 150000 -b:a 20000 -aspect 1280:720 -x264opts "keyint=25:min-keyint=25:no-scenecut:bframes=0" -bluray-compat true -tune stillimage -preset fast -pix_fmt yuv420p -acodec aac -metadata language=en -f mpegts -flush_packets 0 'srt://127.0.0.1:5001'

Find Examples