embedding WebRTC as RTMP re-publishing

Embedding of WebRTC republishing as RTMP into HTML5 page

Web Call Server converts a WebRTC audio + video stream to RTMP and sends it to the specified RTMP server

Use these instructions for quick installation and configuration of the server. In addition to that, you can connect to our demo server demo.flashphoner.com via the Websockets protocol to perform the tests.

Step-by-step instructions for embedding of WebRTC republishing as RTMP on web page

To embed WebRTC as RTMP republishing in an HTML5 page, create two empty files webrtc-as-rtmp-republishing-min.html and webrtc-as-rtmp-republishing-min.js. These files will contain the minimum code.

Let us analyze the contents of the files

HTML

Place the necessary elements in webrtc-as-rtmp-republishing-min.html:

1. Import the script of the main API

<script type="text/javascript" src="https://flashphoner.com/downloads/builds/flashphoner_client/wcs_api-2.0/current/flashphoner.js"></script>

2. Import the script for republishing

<script type="text/javascript" src="webrtc-as-rtmp-republishing-min.js"></script>   

3. Initialize the API on page load

<body onload="init_page()">

4. Add a div element in which the republished video stream will be displayed

<div id="localvideo" style="width:320px;height:240px;border: solid 1px"></div>

5. Add another div element in which a link for playing the video stream in the player will be displayed

<div id="rtmpurl"></div>

View of the resulting web page is in the screenshot below

before clicking publish WEBRTC RTMP republishing WCS

 

The full code of the HTML page looks as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="https://flashphoner.com/downloads/builds/flashphoner_client/wcs_api-2.0/current/flashphoner.js"></script>
    <script type="text/javascript" src="webrtc-as-rtmp-republishing-min.js"></script>
</head>
<body onload="init_page()">
    <div id="localVideo" style="width:320px;height:240px;border: solid 1px"></div>
<br>
    <input type="button" onclick="connect()" value="Publish"/>
<br>
<br> 
	<div id="rtmpurl"></div>		
</body>
</html>

JavaScript

1. Create the constants for the server operation status

var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;

2. Create the variable for the Websocket session

var session;

3. Initialize API when the HTML page is loaded

function init_page() {
    Flashphoner.init({});
}

4. Connect to the WCS server via Websocket. In this example, we are using our demo server. To test your own server, replace “wss://demo.flashphoner.com” with your WCS address

function connect() {
    session = Flashphoner.createSession({
        urlServer: "wss://demo.flashphoner.com:8443"
    }).on(SESSION_STATUS.ESTABLISHED, function(session) {
        publishStream(session);
    });
}

5. Next, publish the session.createStream() stream and pass the stream name “mystream”, HTML element “localVideo” and the RTMP server URL for republishing as parameters

function publishStream(session) {
	var stream = "mystream"
	var rtmpUrl = "rtmp://demo.flashphoner.com:1935/live";
    session.createStream({
        name: stream,
        display: document.getElementById("localVideo"),
        rtmpUrl: rtmpUrl
    }).publish();
}

6. Then form a link to the republished stream and display it on the web-page

var url = rtmpUrl + "/" + "rtmp_" + stream;
	document.getElementById("rtmpurl").textContent = url;
}

The full JavaScript code looks as follows:

 var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
var session;

function init_page() {
    Flashphoner.init({});
}

function connect() {
    session = Flashphoner.createSession({
        urlServer: "wss://demo.flashphoner.com:8443"
    }).on(SESSION_STATUS.ESTABLISHED, function(session) {
        publishStream(session);
    });
}

function publishStream(session) {
    var stream = "mystream"
    var rtmpUrl = "rtmp://demo.flashphoner.com:1935/live";
    session.createStream({
        name: stream,
        display: document.getElementById("localVideo"),
        rtmpUrl: rtmpUrl
    }).publish();
    var url = rtmpUrl + "/" + "rtmp_" + stream;
    document.getElementById("rtmpurl").textContent = url;
}

General view of the web page after clicking on the “Publish” button

after clicking publish WEBRTC RTMP republishing WCS

Copy the link to the stream and open it using the VLC player

URL to VLC player publish WEBRTC RTMP republishing WCS

Playing a republished video stream in the VLC player

publish play browser VLC publish WEBRTC RTMP republishing WCS

Download Web Call Server 5

System requirements: Linux x86_64, 1 core CPU, 2 Gb RAM, Java

    Download Now    

Installation:

  1. wget https://flashphoner.com/download-wcs5.2-server.tar.gz
  2. Unpack and install using 'install.sh'
  3. Launch server using command 'service webcallserver start'
  4. Open the web interface https://host:8444 and activate your license

 

If you are using Amazon EC2, you don't need to download anything.

Launch WCS5 on Amazon EC2

 

Web Call Server Monthly Subscription

$75 per month

 

   Purchase   

 


Related Articles