Table of Contents

Join a Room with Stream

Connecting and joining a Room is a complex chain of events. You will need to ensure success status of previous event to proceed to the next event. The following basic steps are required to join room successfully

  • Initiate Room & Connect
  • If connected, initiate Stream.
  • Publish Stream

joinRoom() method comes as a handy tool for developer. It handles all complexities of connecting and joining the room.

Method: JoinRoom(token,publishStreamInfo,roomInfo,success,error)

Parameters:

  • @param {String} token -it is encoded token string received from Enx application server.
  • @param {JSON} publishStreamInfo - publishStreamInfo for local streams
  • @param {JSON} - roomInfo - room info for joining room
  • @param {SuccessCallback}
  • @param {ErrorCallback}
var streamOpt = {
audio: true,
video: true,
data: true,
audioOnlyMode: false,
audioMuted: false,
videoMuted: false,
maxVideoLayers: 1,
name: "Shashank"
};
var playerConfiguration = {
audiomute: true,
videomute: true,
bandwidth: true,
screenshot: true,
avatar: true,
iconHeight: 30,
iconWidth: 30,avatarHeight: 200,
avatarWidth: 200,
};
var roomOpt = {
activeviews: "list",
allow_reconnect: true,
number_of_attempts: 3,
timeout_interval: 15,
playerConfiguration: playerConfiguration,
forceTurn: false,
chat_only: false,
};
window.EnxRtc.joinRoom(result.token, streamOpt,roomOpt, function
(data) {
console.log( JSON.stringify(data.data));
initLocalView(); // To init local View
initRemoteView(); // To init Remote View
}, function (err) {
}
);

Event Listeners:

  • onRoomConnected – When Client End Point is connected to the room successfully
  • onRoomDisConnected – When Client End Point gets disconnected from the room
  • onRoomError – When Client End Point’s attempt to connect to room fails
  • onUserConnected – Everyone is notified that a new user is connected to the Room
  • onUserDisConnected – Everyone is notified that a user is disconnected from the Room
  • onConnectionLost – When End Point loses network connection
  • onConnectionInterrupted – When the connection is interrupted e.g Switch from WiFi to 4G and vice versa
  • onUserReconnectSuccess – When End-Point successfully gets reconnected with EnableX
  • onReconnect – When End-Point tries to reconnect within the given time period.
  • onPublishedStream – Publisher is notified that its Stream has been published into the Room
  • onUnPublishedStream – Publisher is notified that its Stream is unpublished/removed from the Room.
// Add Event Listeners
window.EnxRtc.addEventListner("onRoomConnected", function
(data) {
console.log( JSON.stringify(data.data));
});
window.EnxRtc.addEventListner("onRoomError", function
(data) {
console.log( JSON.stringify(data.data));
initLocalView(); // To init local View
initRemoteView(); // To init Remote View
});
window.EnxRtc.addEventListner("onEventError", function (data) {
console.log(JSON.stringify(data.data));
});window.EnxRtc.addEventListner("onUserConnected", function (data) {
console.log(JSON.stringify(data.data));
});
window.EnxRtc.addEventListner("onUserDisConnected", function (data) {
console.log( JSON.stringify(data.data));
});

Initiate Local and Remote View

These methods are used to show local and remote streams. Users must initiate local and remote views in the success of the room-connected event.

Method:

initLocalView( localviewOptions, successCallback, errorCallback )

Parameters:

  • @param {JSON} localviewOptions – JSON object defining the display attributes as given below:
    • height
    • width
    • margin_top
    • margin_left
    • margin_right
    • margin_bottom
    • position
  • @param {SuccessCallback}
  • @param {ErrorCallback}
// To Init Local View
var initLocalViewOptions = {
height: 130,
width: 100,
margin_top: 50,
margin_left: 0,
margin_right: 15,
margin_bottom: 10,
position: "top"
};
window.EnxRtc.initLocalView(initLocalViewOptions,
function
(data) {
console.log(JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));});

Method:

initRemoteView( remoteviewOptions, successCallback, errorCallback )

Parameters:

  • @param {JSON} remoteviewOptions – JSON object defining the display attributes as given below:
    • height
    • width
    • margin_top
    • margin_left
    • margin_right
    • margin_bottom
    • position
  • @param {SuccessCallback}
  • @param {ErrorCallback}
// To init Remote View
var initRemoteViewOptions = {
height: 600,
width: 800,
margin_top: 100,
margin_left: 0,
margin_right: 15,
margin_bottom: 10,
position: "center"
};
window.EnxRtc.initRemoteView(initRemoteViewOptions, function
(data) {
console.log( JSON.stringify(data.data));
}, function (err) {
console.log(JSON.stringify(err));
});

Disconnect from a Room

A Client End Point can disconnect itself from the room to close its session. A disconnected End-Point will lose media and signaling socket immediately.

Method: disconnect() – Without any parameter

Event Listeners:

  • onRoomDisconnected – To the user who gets disconnected
  • onUserDisconnected – To all other connected users
window.EnxRtc.disconnect();
// Notified User who is disconnected .
window.EnxRtc.addEventListner("onRoomDisConnected",
console.log(JSON.stringify(data.data));
});
// Other users in the room is notified.
function (data)
{window.EnxRtc.addEventListner("onUserDisConnected",
function (data)
{
console.log(JSON.stringify(data.data));
});