Table of Contents |
---|
Example of streamer with recording of several published video streams in one session
This streamer can be used to publish and record several WebRTC streams simutaneously to Web Call Server in one session.
Warning |
---|
This example does not work in iOS Safari. It is recommended to use desktop PC/Mac browser. |
On the screenshot below 5 streams are publishing and recording
Code of the example
The path to the source code of the example on WCS server is:
...
Here host is the address of the WCS server.
...
Analyzing the code
To analyze the code, let's take the version of file several_streams_recording.js with hash 51703a2 ecbadc3 which is available available here and can be downloaded in build build 2.0.5.28.2753.141212.
1. Initialization of the API
Flashphoner.init() code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'}); |
2. Connection to server.
Flashphoner.createSession() code
Code Block | ||||
---|---|---|---|---|
| ||||
testSession = Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function (session) { addSessionStatusLog(session); //session connected, start playback publishStreams(session);... }).on(SESSION_STATUS.DISCONNECTED, function (session) { addSessionStatusLog(session); toInitialState();... }).on(SESSION_STATUS.FAILED, function (session) { addSessionStatusLog(session); toInitialState();... }); |
3. Receiving the event confirming successful connection
ConnectionStatusEvent ESTABLISHED ESTABLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
testSession = Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function (session) { addSessionStatusLog(session); //session connected, start playback publishStreams(session); }).on(SESSION_STATUS.DISCONNECTED, function (session) { ... }); |
...
session.createStream(), publish() code
When stream is created, the following parameters are passed
...
StreamStatusEvent PUBLISHING code
Code Block | ||||
---|---|---|---|---|
| ||||
var stream = session.createStream({ ... }).on(STREAM_STATUS.PUBLISHING, function (stream) { checkCountStreams(); addStatusLog(stream); ... }); |
6. Streams count checking and publishing new streams until desired value is reached
Code Block | ||||
---|---|---|---|---|
| ||||
function checkCountStreams() { var $publishBtn = $("#publishBtn"); if ($publishBtn.text() === "Start" && $publishBtn.prop('disabled') ) { if (streams.length < $("#countStreams").val()) { publishStreams(session); } else { toRecordedState(); } } } |
7. Streaming stop
stream.stop() code
Code Block | ||||
---|---|---|---|---|
| ||||
function toRecordedState() { $("#publishBtn").text("Stop").off('click').click(function () { for (var i in streams) { streams[i].stop(); } streams = []; toInitialState(); }).prop('disabled', false); } |
...
StreamStatusEvent UNPUBLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
var stream = session.createStream({ ... }).on(STREAM_STATUS.UNPUBLISHED, function (stream) { checkCountStreams(); addStatusLog(stream); }).on(STREAM_STATUS.FAILED, function (stream) { ... }); |