Connecting to a Session
This page covers the full connection lifecycle for a Cordova video session: enumerating media devices, joining a room, rendering local and remote video views, handling reconnection, and gracefully disconnecting when the session ends.
Before joining a room you can enumerate the audio and video devices available on the device. This lets you build a device-selection UI or verify that the required hardware is present.
Get All Audio / Video Devices
getDevices() returns a list of all microphones and cameras connected to the device, along
with their device IDs. Use this list to populate a device-picker or to pick a specific device ID for
the stream configuration.
- Method:
window.EnxRtc.getDevices(successCallback, errorCallback)
window.EnxRtc.getDevices(
function(data) {
console.log("Available devices:", JSON.stringify(data.data));
// data.data is an array of { deviceId, label, kind } objects
},
function(err) {
console.error("getDevices failed:", JSON.stringify(err));
}
);
Get the Currently Selected Device
getSelectedDevice() returns the audio/video device currently in use for the published
stream. Call this after joining to confirm which device is active.
- Method:
window.EnxRtc.getSelectedDevice(successCallback, errorCallback)
window.EnxRtc.getSelectedDevice(
function(data) {
console.log("Selected device:", JSON.stringify(data.data));
},
function(err) {
console.error("getSelectedDevice failed:", JSON.stringify(err));
}
);
Connecting to an EnableX room normally involves multiple sequential steps: initialise the room, check
media access, publish the local stream, and confirm publication. joinRoom() compresses all
of these steps into a single call so you can get the session running quickly.
The method accepts three JSON configuration objects: one for the local media stream, one for the room
behaviour, and then success/error callbacks. After joinRoom() returns successfully, call
initLocalView() and initRemoteView() to render video.
- Method:
window.EnxRtc.joinRoom(token, publishStreamInfo, roomInfo, successCallback, errorCallback)
Parameters
| Parameter | Type | Description |
|---|---|---|
token | String | Signed JWT issued by your server for this user |
publishStreamInfo | JSON Object | Local stream configuration (see below) |
roomInfo | JSON Object | Room behaviour options (see below) |
successCallback | Function | Called when the join request is accepted |
errorCallback | Function | Called if the join request fails |
publishStreamInfo Options
| Key | Type | Description |
|---|---|---|
audio | Boolean | Enable audio track in the local stream |
video | Boolean | Enable video track in the local stream |
data | Boolean | Enable data channel for chat and signaling |
audioOnlyMode | Boolean | Join in audio-only mode; no video published or received |
audioMuted | Boolean | Start with microphone muted |
videoMuted | Boolean | Start with camera muted |
maxVideoLayers | Number | Maximum simulcast video layers to publish |
name | String | Display name shown to other participants |
roomInfo Options
| Key | Type | Description |
|---|---|---|
activeviews | String | View layout mode, e.g. "list" |
allow_reconnect | Boolean | Allow automatic reconnection on network drop |
number_of_attempts | Number | Maximum reconnection attempts |
timeout_interval | Number | Seconds between reconnection attempts |
playerConfiguration | JSON Object | Player UI controls and avatar sizing |
forceTurn | Boolean | Force all media through TURN relay |
chat_only | Boolean | Join as a chat-only participant (no media) |
Event Listeners
| Event | Fired To | Description |
|---|---|---|
onRoomConnected | Self | Successfully connected to the room |
onRoomError | Self | Connection to the room failed |
onRoomDisConnected | Self | Disconnected from the room |
onUserConnected | All others | A new participant joined the room |
onUserDisConnected | All others | A participant left the room |
onPublishedStream | Self | Local stream successfully published |
onUnPublishedStream | Self | Local stream unpublished from the room |
onConnectionLost | Self | Network connection lost |
onConnectionInterrupted | Self | Connection interrupted (e.g. WiFi to 4G switch) |
onUserReconnectSuccess | Self | Reconnected successfully after a drop |
onReconnect | Self | Reconnection attempt in progress |
// Stream configuration
var streamOpt = {
audio: true,
video: true,
data: true,
audioOnlyMode: false,
audioMuted: false,
videoMuted: false,
maxVideoLayers: 1,
name: "John"
};
// Player UI controls embedded in roomInfo
var playerConfiguration = {
audiomute: true,
videomute: true,
bandwidth: true,
screenshot: true,
avatar: true,
iconHeight: 30,
iconWidth: 30,
avatarHeight: 200,
avatarWidth: 200
};
// Room behaviour options
var roomOpt = {
activeviews: "list",
allow_reconnect: true,
number_of_attempts: 3,
timeout_interval: 15,
playerConfiguration: playerConfiguration,
forceTurn: false,
chat_only: false
};
// Register listeners before joining
window.EnxRtc.addEventListner("onRoomConnected", function(data) {
console.log("Connected:", JSON.stringify(data.data));
initLocalView(); // Render local video
initRemoteView(); // Render remote video
});
window.EnxRtc.addEventListner("onRoomError", function(data) {
console.error("Room error:", JSON.stringify(data.data));
});
window.EnxRtc.addEventListner("onUserConnected", function(data) {
console.log("User joined:", JSON.stringify(data.data));
});
window.EnxRtc.addEventListner("onUserDisConnected", function(data) {
console.log("User left:", JSON.stringify(data.data));
});
// Join the room
window.EnxRtc.joinRoom(
result.token,
streamOpt,
roomOpt,
function(data) { console.log("Join OK:", JSON.stringify(data.data)); },
function(err) { console.error("Join failed:", JSON.stringify(err)); }
);
After the room is connected, you need to create two native view containers: one for the local camera
feed and one for remote participants. Call these methods inside your onRoomConnected
listener.
Initialise the Local View
initLocalView() creates and positions the native view that renders your own camera stream.
Pass a localviewOptions object to control the size and position of the view.
- Method:
window.EnxRtc.initLocalView(localviewOptions, successCallback, errorCallback)
| Key | Type | Description |
|---|---|---|
height | Number | View height in points |
width | Number | View width in points |
margin_top | Number | Top margin offset |
margin_left | Number | Left margin offset |
margin_right | Number | Right margin offset |
margin_bottom | Number | Bottom margin offset |
position | String | Positional hint (e.g. "top") |
function initLocalView() {
var localViewOptions = {
height: 130,
width: 100,
margin_top: 50,
margin_left: 0,
margin_right: 15,
margin_bottom: 10,
position: "top"
};
window.EnxRtc.initLocalView(
localViewOptions,
function(data) { console.log("Local view ready:", JSON.stringify(data.data)); },
function(err) { console.error("Local view error:", JSON.stringify(err)); }
);
}
Initialise the Remote View
initRemoteView() creates and positions the native view that renders remote participants'
streams. Call this alongside initLocalView() after the room connects.
- Method:
window.EnxRtc.initRemoteView(remoteviewOptions, successCallback, errorCallback)
function initRemoteView() {
var remoteViewOptions = {
height: 600,
width: 800,
margin_top: 100,
margin_left: 0,
margin_right: 15,
margin_bottom: 10,
position: "center"
};
window.EnxRtc.initRemoteView(
remoteViewOptions,
function(data) { console.log("Remote view ready:", JSON.stringify(data.data)); },
function(err) { console.error("Remote view error:", JSON.stringify(err)); }
);
}
If a user's network drops or switches (e.g. from WiFi to mobile data), the SDK fires a sequence of reconnection events. You can listen to these to show UI feedback and restore the session state when the connection comes back.
// Network connection lost
window.EnxRtc.addEventListner("onConnectionLost", function(data) {
console.warn("Connection lost. Attempting to reconnect...");
showReconnectingBanner();
});
// A reconnection attempt is underway
window.EnxRtc.addEventListner("onReconnect", function(data) {
console.log("Reconnecting:", JSON.stringify(data.data));
});
// Reconnection succeeded
window.EnxRtc.addEventListner("onUserReconnectSuccess", function(data) {
console.log("Reconnected successfully:", JSON.stringify(data.data));
hideReconnectingBanner();
});
Call disconnect() to close the session for the local user. The endpoint immediately loses
media and signaling. All other participants in the room receive an onUserDisConnected
notification.
- Method:
window.EnxRtc.disconnect()
| Event | Fired To | Description |
|---|---|---|
onRoomDisConnected | Self | Confirms disconnection for the local user |
onUserDisConnected | All others | Notifies remaining participants that this user left |
// Disconnect the local user
window.EnxRtc.disconnect();
// Confirmation for the disconnected user
window.EnxRtc.addEventListner("onRoomDisConnected", function(data) {
console.log("You have left the room:", JSON.stringify(data.data));
navigateToHomeScreen();
});
// Notification to everyone else
window.EnxRtc.addEventListner("onUserDisConnected", function(data) {
console.log("A participant left:", JSON.stringify(data.data));
removeParticipantFromUI(data.data.clientId);
});