/

Auto Failover and Order


Auto Failover and Order

While you can specifically target a publisher - as described in the previous sections for WebRTC Publisher and Flash/RTMP Publisher - you may want to let the Red5 Pro HTML SDK select the optimal publisher based on browser support for the technologies.

As you may have noticed form the previous sections, the source configuration for each publisher has differing property requirements. This is due simply to the technologies and broadcast strategies that each use:

  • The WebRTC player utilizes WebSockets, WebRTC and getUserMedia to publish a video and to be displayed in an HTML5 video element.
  • The Flash/RTMP player utilizes a SWF file to broadcast and view streaming video from the Flash Player plugin.

As such, the init configuration provided to the library to allow for auto-failover player selection should be provided with attributes defining the target source(s) - i.e., rtc and/or rtmp:

index.html:

<!doctype html>
<html>
  <head>
    <!-- Recommended shim for cross-browser WebRTC support. -->
    <script src="https://webrtchacks.github.io/adapter/adapter-latest.js"></script>
  </head>
  <body>
    <video id="red5pro-publisher" autoplay muted></video>
    <!-- Exposes `red5prosdk` on the window global. -->
    <script src="lib/red5pro/red5pro-sdk.min.js"></script>
    <!-- Example script below. -->
    <script src="main.js"></script>
  </body>
</html>

main.js:

...
(function (red5prosdk) {

  // Create a new instance of the failover publisher.
  var publisher = new red5prosdk.Red5ProPublisher();

  // Set publish order and initialize
  publisher
    .setPublishOrder(['rtc', 'rtmp'])
    .init({
      "rtc": {
        // See above documentation for WebRTC source option requirements.
      },
      "rtmp": {
        // See above documentation for RTMP source option requirements.
      }
    })
    .then(function(selectedPublisher) {

      // Publisher implementation determined based on order and browser support.
      return selectedPublisher.publish();
    })
    .then(function() {
      // Publishing has initiated successfully.
    })
    .catch(function(error) {
      // An error occurred witin the initialization and publish process.
    });

})(window.red5prosdk);