1. Overview
  2. Start a Call
  3. Send Media Event
  4. Receive Media Event
  5. Share Screen
  6. Stop a Call

1 Overview

When users are in a space together they can have a video call. This tutorial outlines how to perform the main tasks associated with managing a audio/video call. Avaya Spaces uses Socket.io to communicate presence and initiate and control audio/video. This tutorial assumes knowledge of connecting socket.io, joining and subscribing to a space with socket.io (see Send and Receive Messages Tutorial).

2 Start a Call

Once a user subscribes to a space, send a presence event to notify Avaya Spaces and other members of the space that the user is online. To do this emit the following socket event:SEND_PRESENCE_EVENT. Like so:

var payload = {
    "category": "app.event.presence.party.online",
    "topicId": "5949579a7ec01d05d30054e1",
    "content": {
        "desktop": false,
        "idle": false,
        "mediaSession": {
            "audio": false,
            "connected": false,
            "phone": false,
            "screenshare": false,
            "selfMuted": true,
            "video": false
        },
        "offline": false,
        "role": "admin"
    }
};

socketConnection.emit('SEND_PRESENCE_EVENT', payload);

Note: app.event.presence.party.online is the category of presence event to emit when coming online in a space.

Next, to start an audio/video call send the SEND_MEDIA_SESSION_EVENTS socket event. Like this:

var payload = {
    "category": "tracksstatus",
    "topicId": "5949579a7ec01d05d30054e1",
    "content": {
        "mediaSession": {
            "audio": false,
            "connected": false,
            "phone": false,
            "screenshare": false,
            "selfMuted": true,
            "video": false
        },
        "streamId": "pDxXfjT1nNGvLCW9egl8AJDeBFESw8j0Ypf8"
    },
    "sender": {
        "_id": "593807c13b3132a1e27c806d",
        "type": "user"
    }
};

socketConnection.emit('SEND_MEDIA_SESSION_EVENTS', payload);

At this point the user is in a call with their default settings enabled. Other online members of the space will see that a call has started and can shoose to join.

3 Send Media Event

To notify other members of the call that we have toggled our local audio or video, we must emit another SEND_MEDIA_SESSION_EVENTSsocket event with the new media session state. The category should be tracksstatus. For example:

var payload = {
    "category": "tracksstatus",
    "topicId": "5949579a7ec01d05d30054e1",
    "content": {
        "mediaSession": {
            "audio": true,
            "connected": true,
            "phone": false,
            "screenshare": false,
            "selfMuted": false,
            "video": true
        },
        "streamId": "pDxXfjT1nNGvLCW9egl8AJDeBFESw8j0Ypf8" //*****/
    },
    "sender": {
        "_id": "593807c13b3132a1e27c806d",
        "type": "user"
    }
};

socketConnection.emit('SEND_MEDIA_SESSION_EVENTS', payload);

This example is what would be sent when the user unmutes the local audio and video. The SEND_MEDIA_SESSION_EVENTS should be emitted each time the local media state changes.

4 Receive Media Event

To receive changes in the state of the media session listen for the socket event MEDIA_SESSION_RESPONSE. Any changes such as members joining or leaving will be received as this socket event, the payload will include the updated state. For example:

socketConnection.on('MEDIA_SESSION_RESPONSE', function(payload) {
    console.log(payload);
});

The payload will look something like this:

{
    "category": "tracksstatus",
    "topicId": "5949579a7ec01d05d30054e1",
    "content": {
        "mediaSession": {
            "audio": true,
            "connected": true,
            "phone": false,
            "screenshare": false,
            "selfMuted": false,
            "video": true
        },
        "streamId": "pDxXfjT1nNGvLCW9egl8AJDeBFESw8j0Ypf8" //*****/
    },
    "sender": {
        "_id": "593807c13b3132a1e27c806d",
        "displayname": "Kevin Bacon",
        "picture_url": "https://accounts.avayacloud.com/norevimages/noimage.jpg",
        "type": "user",
        "username": "kevinb@fakeemail.com"
    }
}

This is what the payload would look like if another member of the space started a video call. To join the call simply send the SEND_MEDIA_SESSION_EVENTS socket event with the updated media session state as in section 3.

5 Share Screen

To begin screen sharing with other parties of the space currently on the call, we start by sending the SEND_MEDIA_SESSION_EVENTS socket event. The category is video.startscreenshare. This will notify members of the space that a screen will be shared. For example:

var payload = {
    "category": "video.startscreenshare",
    "content": {
        "streamId": "qsj9Zal8xpDHi9OZjSObxq0NuS6tFmbpPfPs"
    },
    "sender": {
        "_id": "593807c13b3132a1e27c8061",
        "type": "user"
    },
    "topicId": "59404b947ec01d05d3004f81"
};

socketConnection.emit('SEND_MEDIA_SESSION_EVENTS', payload);

Next, obtain URLs to upload the frames of the screen to be shared. Send a SEND_MEDIA_SESSION_EVENTS socket event with the category video.screenshare.uploadurl. Like so:

var payload = {
    "category": "video.screenshare.uploadurl",
    "content":  {
        "Content-Type": "image/jpeg"
    },
    "sender": {
        "_id": "593807c13b3132a1e27c8061",
        "type": "user"
    },
    "topicId": "59404b947ec01d05d3004f83"
};

socketConnection.emit('SEND_MEDIA_SESSION_EVENTS', payload);

Avaya Spaces will send a MEDIA_SESSION_RESPONSE socket event with 10 URLs to be used to upload the next 10 frames of the screen. For example:

socketConnection.on('MEDIA_SESSION_RESPONSE', callback(payload));

The payload received from the server will look like this:

{
    "category": "video.screenshare.uploadurl",
    "content": {
        "expires": "2017-07-04T16:11:30.181Z",
        "files":    [
            {
                "fileKey": "screen_59404b947ec01d05d3004f63/1",
                "downloadurl": "URL",
                "uploadurl": "URL"
            }
        ],
        "sessionId": "505123c8-4a95-49cc-985e-e0aa3ffa0e42"
    },
    "sender": {
        "_id": "593807c13b3132a1e27c8061",
        "type": "user"
    },
    "topicId": "59404b947ec01d05d3004f83"
}

The files array will include 10 objects like the one shown, each with unique fileKey, downloadurl and uploadurl. Frames are to be uploaded sequentially to the 10 URLs provided. For example: frame 1 should be upload to the URL in file[0], frame 2 to file[1],..., frame 10 to file[9], frame 11 to file[0], etc...

When each frame is uploaded we should send the SEND_MEDIA_SESSION_EVENTS socket event to notify other parties to download the uploaded frame. For example, send the following payload:

{
    "category": "video.screensharedata",
    "content":  {
        "height": 1080,
        "image": "DOWNLOAD_URL",
        "timeUploaded": 1499177492483,
        "width": 1920
    },
    "sender": {
        "_id": "593807c13b3132a1e27c8069",
        "type": "user"
    },
    "topicId": "59404b947ec01d05d3004f83"
}
height
Height of the frame in pixels
image
Download URL of the frame uploaded
timeUploaded
Timestamp of upload time
width
Width of frame in pixels

When the screen is no longer being shared, send the SEND_MEDIA_SESSION_EVENTS with category video.stopscreenshare. Like so:

{
    "category": "video.stopscreenshare",
    "content": {
        "streamId": "7XxlO8fBzMAQTHPVuL6M62ZjvY7vq7Lxqlsv"
    },
    "sender":   {
        "_id": "593807c13b3132a1e27c8061",
        "type": "user"
    },
    "topicId": "59404b947ec01d05d3004f81"
}

6 Stop a Call

When a user no longer wants to participate in a call they can leave the media session. Send the SEND_MEDIA_SESSION_EVENTS socket event. The category should be video.end. For example:

var payload = {
    "category": "video.end",
    "topicId": "5949579a7ec01d05d30054e1",
    "sender": {
        "_id": "593807c13b3132a1e27c806d",
        "type": "user"
    }
};

socketConnection.emit('SEND_MEDIA_SESSION_EVENTS', payload);

This category with the socket event MEDIA_SESSION_RESPONSE will also be received when another party ends their participation in the call.