Skip to content

Softvelum/webrtcjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebRTC Javascript library

WebRTC JavaScript publisher library allows adding WebRTC publishing capabilities to your web pages. It uses WHIP signaling.

Use its code in your projects or take it as is for embedding into your pages to connect your users to Nimble Streamer. To learn more about server setup, read WebRTC setup article.

The following codecs can be used:

Specific codecs can be set via "videocodecs" parameter is WHIP URL.

Use demo publishing page to publish to your Nimble Streamer instance.

Getting Started

Add library to HTML

<script defer="defer" src="e32af6a81c16a82154b7.bundle.js"></script>

Usage

var config = {
  whipUrl: 'https://127.0.0.1:8443/live/whip?whipauth=username:password'
};
var publisher = new WebRTCjs(config);
publisher.publish();

Full example

<!DOCTYPE html>
<html>
  <head>
    <script defer="defer" src="e32af6a81c16a82154b7.bundle.js"></script>
  </head>
  <body>
    <script type="text/javascript">
      document.addEventListener("DOMContentLoaded", function(event) {
        var config = {
          whipUrl: 'https://127.0.0.1:8443/live/whip?whipauth=username:password',
        };
        var publisher = new WebRTCjs(config);
        publisher.publish();
      });
    </script>
  </body>
</html>

Configuration options

  • whipUrl - publishing URL with authorization parameters.
  • logLevel - the log level: info, or error.
  • videoElement - <video> tag to local monitoring published stream.
  • videoSelect - <select> tag with available cameras.

Callbacks

  • onPublisherCreated - called when publisher instance has been created with the provided configuration. Parameters: settings.
  • onConnectionStateChange - called when connection state has changed. Parameters: connectionState.
  • onOffer - called when SDP offer is ready. Parameters: offer.
  • onAnswer - called when server answer has been received. Parameters: answer.
  • onConnectionError - called if connection error happens. Has no parameters.

Callback usage example

var config = {
  whipUrl: 'https://127.0.0.1:8443/live/whip?whipauth=username:password',

  onPublisherCreated: function(settings){ console.log('Ready to WebRTC publishing'); }
};

Related documentation