Versions Compared

Key

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

...

Здесь host - адрес WCS-сервера.

Work with code of MCU conference participant

...

Работа с кодом примера

Для разбора кода возьмем файл mcu_client.js, which is available here and can be downloaded with corresponding build который находится здесь и доступен для скачивания в соответствующей сборке 0.5.28.2753.123.

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
    Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function (session) {
        setStatus(session.status());
        //session connected, start playback
        startStreaming(session);
    }).on(SESSION_STATUS.DISCONNECTED, function () {
        setStatus(SESSION_STATUS.DISCONNECTED);
        onStopped();
    }).on(SESSION_STATUS.FAILED, function () {
        setStatus(SESSION_STATUS.FAILED);
        onStopped();
    })

3. Receiving the event confirming successful connectionConnectionStatusEvent ESTABLISHED codeПолучение от сервера события, подтверждающего успешное соединение

ConnectionStatusEvent ESTABLISHED код

On receiving the event, streaming is started

...

4. Get audio publishing and playing constraints from the client page

getConstraints()  codeкод

Audio constraint: true or false (depending on the value both published and played stream will have or have not audio)

...

session.createStream(), publish()  code код

When stream is created, the following parameters are passed

  • streamName - name of the stream (имя поток, публикуемого участником конференции (в данном случае login + "#" + roomName in this case, where login is the name of the participantгде login - имя участника)
  • mockLocalDisplay - div- <div> elementэлемент, required for the local camera video (will not be displayed to the user in the case)
  • constraints - getConstraints()  code код (in this case is used to specify if the published stream will have audio)

...

6. Receiving the event confirming successful streaming

StreamStatusEvent PUBLISHING codePUBLISHING код

On receiving the event, a stream for playing the participant's conference mixer is created

Code Block
languagejs
themeRDark
    publishStream = session.createStream({
        ...
    }).on(STREAM_STATUS.PUBLISHING, function (publishStream) {
        //play preview
        playStream(session);
        ...
    });

7. Playback of conference streamВоспроизведение потока конференцции

session.createStream(), play()  code код

When stream is created, the following parameters are passed

  • streamName - name of the stream (имя микшера, кторый будет воспроизводиться для участника (в данном случае roomName + "-" + login + roomName in this case, where login is the name of the participantгде login - имя участника)
  • remoteVideo - div- <div> element, in which the video will be displayedэлемент, в котором будет отображаться видео
  • constraints - getConstraints()  code код (in this case is used to specify if the played stream will have audio)

...

Code Block
languagejs
themeRDark
    conferenceStream = session.createStream({
        name: streamName,
        display: remoteVideo,
        constraints: getConstraints()
    }).on(STREAM_STATUS.PENDING, function (stream) {
        ...
    }).on(STREAM_STATUS.PLAYING, function (stream) {
        $("#preloader").hide();
        setStatus(stream.status());
        onStarted();
    }).on(STREAM_STATUS.STOPPED, function () {
        ...
    }).on(STREAM_STATUS.FAILED, function (stream) {
       ...
    });

9. Stop of playback and streaming on leaving the conferenceОстановка публикации и воспроизведения видеопотоков при отключении от конференции

stopStreams() code код

Code Block
languagejs
themeRDark
    conferenceStream.stop();
    publishStream.stop();

10. Receiving the event confirming playback successful streaming stop

StreamStatusEvent STOPPED codeUNPUBLISHED код

Code Block
languagejs
themeRDark
    conferenceStreampublishStream = session.createStream({
        name: streamName,
        display: remoteVideomockLocalDisplay,
        constraintsreceiveVideo: getConstraints()false,
     }).on(STREAM_STATUS.PENDING, function (stream) {
   receiveAudio: false,
         ...constraints: getConstraints()
    }).on(STREAM_STATUS.PLAYINGPUBLISHING, function (streampublishStream) {
        ...
    }).on(STREAM_STATUS.STOPPEDUNPUBLISHED, function () {
        $("#preloader").hide();
        setStatus(STREAM_STATUS.STOPPED);
        onStopped();
    }).on(STREAM_STATUS.FAILED, function (stream) {
        ...
    });

11. Receiving the event confirming successful streaming playback stop

StreamStatusEvent UNPUBLISHED codeSTOPPED код

Code Block
languagejs
themeRDark
    publishStreamconferenceStream = session.createStream({
        name: streamName,
        display: mockLocalDisplayremoteVideo,
        receiveVideoconstraints: false,getConstraints()
    }).on(STREAM_STATUS.PENDING, function   receiveAudio: false,(stream) {
        constraints: getConstraints()...
    }).on(STREAM_STATUS.PUBLISHINGPLAYING, function (publishStreamstream) {
        ...
    }).on(STREAM_STATUS.UNPUBLISHEDSTOPPED, function () {
        $("#preloader").hide();
        setStatus(STREAM_STATUS.STOPPED);
        onStopped();
    }).on(STREAM_STATUS.FAILED, function (stream) {
        ...
    });

...