Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

Since build 5.2.935 in is possible to send an event from publishing client which is biund to the stream published, and to pass the event to all the stream subscribers. Today, the feature is used to notify subscribers when publisher mutes/unmutes audio/video.

Sending stream event from publiher

To send a stream event, the function Stream.sendStreamEvent() is called on client side with event type parameter. For example, stream audio state events are sending when Stream.muteAudio() and Stream.unmuteAudio() are called as follows:

    var muteAudio = function muteAudio() {
      if (mediaConnection) {
        mediaConnection.muteAudio();
        sendStreamEvent(STREAM_EVENT_TYPE.AUDIO_MUTED);
      }
    };
    ...
    var unmuteAudio = function unmuteAudio() {
      if (mediaConnection) {
        mediaConnection.unmuteAudio();
        sendStreamEvent(STREAM_EVENT_TYPE.AUDIO_UNMUTED);
      }
    };

Stream video state events are sending when Stream.muteVideo() and Stream.unmuteVideo() are called:

    var muteVideo = function muteVideo() {
      if (mediaConnection) {
        mediaConnection.muteVideo();
        sendStreamEvent(STREAM_EVENT_TYPE.VIDEO_MUTED);
      }
    };
    ...
    var unmuteVideo = function unmuteVideo() {
      if (mediaConnection) {
        mediaConnection.unmuteVideo();
        sendStreamEvent(STREAM_EVENT_TYPE.VIDEO_UNMUTED);
      }
    };

Receiving stream event on subscribers side

When stream event is passed, all the subscribers receive the STREAM_EVENT event

code

    previewStream = session.createStream({
        name: streamName,
        display: remoteVideo,
        ...
    }).on(STREAM_EVENT, function(streamEvent) {
        switch (streamEvent.type) {
            case STREAM_EVENT_TYPE.AUDIO_MUTED:
                $("#audioMuted").text(true);
                break;
            case STREAM_EVENT_TYPE.AUDIO_UNMUTED:
                $("#audioMuted").text(false);
                break;
            case STREAM_EVENT_TYPE.VIDEO_MUTED:
                $("#videoMuted").text(true);
                break;
            case STREAM_EVENT_TYPE.VIDEO_UNMUTED:
                $("#videoMuted").text(false);
                break;

        }
        console.log("Received streamEvent ", streamEvent.type);
    });

Stream event processing on backend

To process stream events on backend server, sendStreamEvent and StreamEvent methods should be added to the application

add app-rest-method MyAppKey sendStreamEvent
add app-rest-method MyAppKey StreamEvent

Then backend server will receive sendStreamEvent

URL:http://localhost:8081/apps/EchoApp/sendStreamEvent
OBJECT:
{
  "nodeId" : "qg4BeHzYSAtkhUkXgnSMEUZpsshaLPL5@192.168.0.39",
  "appKey" : "defaultApp",
  "sessionId" : "/192.168.0.83:64573/192.168.0.39:8443-a98bb891-aeaf-46a8-8fba-772e07ac035b",
  "mediaSessionId" : "9906b2b0-9c28-11eb-8d20-75f877676678",
  "type" : "audioMuted",
  "info" : "",
  "origin" : "https://wcs:8888"
}

if publisher mutes the stream.

Also, backend will receive StreamEvent per every the stream subscriber

URL:http://localhost:8081/apps/EchoApp/StreamEvent
OBJECT:
{
  "nodeId" : "qg4BeHzYSAtkhUkXgnSMEUZpsshaLPL5@192.168.0.39",
  "appKey" : "defaultApp",
  "sessionId" : "/192.168.0.83:64573/192.168.0.39:8443-a98bb891-aeaf-46a8-8fba-772e07ac035b",
  "mediaSessionId" : "9fed5c50-9c28-11eb-8d20-75f877676678",
  "type" : "audioMuted",
  "info" : ""
}
  • No labels