WebRTC- Broadcasting with Red5

Red5 is an open-source media server that allows you to broadcast live video to many viewers simultaneously.

Red5 Pro builds on Red5, enabling connections through WebRTC. The free trial version allows only 10 connections, but you can pay several hundred USD per month to subscribe to the full versions which let you scale your broadcasting to millions of viewers. Once you have registered for a Red5 Pro license key, you can download the installer and install the software on various platforms including Windows, Ubuntu, and Mac. Red5 Pro also provides other facilities such as video recording.

Note that to use Red5, you should first install Java. At the time of writing, the package that works is JRE_1.8.0_261_64-bit. (You can also install its superset, the JDK). Remember to point the JAVA_HOME environment variable to the root directory of the JRE package. You will need to open up and forward several ports at your router such as 5080, 1935, 8554, and 6262 too.

While webpages are served over the protocol HTTP(S), and Web Sockets connect over WS(S), live videos are broadcast over RTMP(S).

Publisher: For the following to work, the publisher must be connecting from the same machine (localhost) as the Red5 server. For the publisher to connect to a remote Red5 server, you will need to change the protocol (to wss), port (to 443), and host (myremotesite.com) below. You will need to configure Red5 to accept secure TLS (HTTP/WSS) connections by generating the keystore file (keystore.jks) and truststore file (truststore.jks), and then making the necessary modifications in the file conf/red5.properfiles.
<!doctype html><html>
  <head><script src="https://webrtchacks.github.io/adapter/adapter-latest.js"></script>
  </head>
  <body>
     <video id="red5pro-publisher" autoplay muted></video>
     <script src="red5pro-sdk.min.js"></script>
     <script>
       (function (red5prosdk) {
          var publisher = new red5prosdk.RTCPublisher();
          publisher.init({
             protocol: 'ws',    // wss
             port: 5080,        // 443
             host: 'localhost', // myremotesite.com
             app: 'live',
             streamName: 'mystream',
             rtcConfiguration: {
                iceServers:[{urls: 'stun:stun2.l.google.com:19302'}],
                iceCandidatePoolSize: 2,
                bundlePolicy: 'max-bundle'
             },
             streamMode: 'live',
             mediaElementId: 'red5pro-publisher',
             bandwidth: {
                audio: 56,
                video: 512
             },
             mediaConstraints: {
                audio: true,
                video: { width: { exact: 640 },
                         height: { exact: 480 },
                         frameRate: {min: 8, max: 24 }}}
          }).then(function() {
             return publisher.publish();
          }).catch(console.error)
      })(window.red5prosdk);
   </script></body></html>
Subscriber: This shows how to view the video streamed by the publisher. Change some of the properties accordingly should you decide to switch to a secure connection, ie. wss.
<!doctype html><html><head>
   <script src="https://webrtchacks.github.io/adapter/adapter-latest.js"></script>
    <link href="red5pro-media.css" rel="stylesheet">
    <script src="screenfull.min.js"></script></head><body>
    <video id="red5pro-subscriber"
           class="red5pro-media red5pro-media-background"
           autoplay controls>
    </video>
    <script src="red5pro-sdk.min.js"></script>
    <script>
      (function (red5prosdk) {
        var subscriber = new red5prosdk.RTCSubscriber();
        subscriber.init({
           protocol: 'ws',
           port: 5080,
           host: 'my-site.com',
           app: 'live',
           streamName: 'mystream',
           rtcConfiguration: {
               iceServers:[{urls: 'stun:stun2.l.google.com:19302'}],
              iceCandidatePoolSize: 2,
              bundlePolicy: 'max-bundle'},
           mediaElementId: 'red5pro-subscriber',
           subscriptionId: 'mystream' +
                              Math.floor(Math.random() * 0x10000).
                            toString(16),
           videoEncoding: 'NONE',
           audioEncoding: 'NONE'
        }).then(function(subscriber) {
           return subscriber.subscribe();
        }).then(function(subscriber) {
        }).catch(console.error);
      })(window.red5prosdk);
   </script>
</body></html>

Alternative media servers include the Flash Media Server and Wowza. You can also find media host providers (eg. https://www.red5server.com/ ) that host and manage the media servers for you at a monthly fee.