Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Example of streamer with recording of several published video streams in one session

...

On the screenshot below 5 streams are publishing and recording

Image RemovedImage Added

Code of the example

...

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.141.212.

1. Initialization of the API

Flashphoner.init() code

Code Block
languagejs
themeRDark
Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'});

2. Connection to server.

Flashphoner.createSession() code

Code Block
languagejs
themeRDark
    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
languagejs
themeRDark
    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
languagejs
themeRDark
    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

Code Block
languagejs
themeRDark
    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
languagejs
themeRDark
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
languagejs
themeRDark
    var stream = session.createStream({
        ...
    }).on(STREAM_STATUS.UNPUBLISHED, function (stream) {
        checkCountStreams();
        addStatusLog(stream);
    }).on(STREAM_STATUS.FAILED, function (stream) {
        ...
    });