Room Connection

The iOS SDK provides the following methods:

  • init(): To initialize a room.
  • connect(): To connect a client application to a virtual room.
  • joinRoom(): To quickly join a room.
  • disconnect(): To close a session and disconnect a client endpoint from the session.

Initiate a Room

An RTC session occurs in a virtual room hosted on the EnableX platform and the iOS SDK allows client endpoint applications to connect to it. The process starts with initializing a room object by using the EnxRoom class.

Method: -(instancetype)init;

Sample Code

EnxRoom *room = [[EnxRoom alloc] init];

Connect to a Room

The EnxRoom.connect() method connects the client application to the virtual Room hosted on the EnableX server where the RTC session occurs. After initializing the Room, the client endpoint must connect to the Room to establish a bi-directional communication channel over a Web Socket.

As the communication takes place over the web sockets using Socket Events, any network issue leading to the disconnection of the web sockets will cause the communication to fail. In such cases, EnableX offers the option to automatically reconnect with the room.

Note: The automatic reconnection is not applicable when:

  • The last participant has disconnected from the adhoc room.
  • The moderator has dropped the participant from the room.
  • The participant has explicitly disconnected from the room.

Class EnxRoom

Method: - (void)connect:(NSString *)token roomInfo:(NSDictionary *)roomInfo advanceOptions:(NSArray *)advanceOption;

Parameters

Parameter Key Data Type Description
token Not Applicable String A JWT token to connect to the room which is received using the Server API call through the application server.
roomInfo roomInfo.allow_reconnect Boolean

The default value is true. This setting enables automatic reconenction. Set it to false if you do not want client endpoints to try reconnecting to EnableX.

roomInfo.number_of_attempts Numeric

The maximum number of attempts made by a client endpoint to reconnect to EnableX.
The maximum value is not specified. You can use any random number. The minimum value is 1.

The default value is 3.

roomInfo.timeout_interval Numeric Timeout interval in milliseconds required by the client endpoint to wait before attempting to reconnect.
roomInfo.activeviews String
  • Values: list or view
  • Set to view to get a predefined view of all the video streams in a session.
  • Set to list to get individual streams to create your own view with the video streams.
roomInfo.forceTurn Boolean

By default, it is set to false. Set to true to force video streams through a TURN server.

roomInfo.chat_only Boolean

By default, it is set to false. Set to true to enable text-chat only and disable audio-video communication.

roomInfo.playerConfiguration Not Applicable It is a JSON object with video player configurations. audiomute: Boolean. By default, it is set to true. This setting shows the Audio Mute/Unmute button. Set it to false hide this button.
videomute: Boolean. By default, it is set to true. This setting shows the Video Mute/Unmute button. Set it to false hide this button.
bandwidth: Boolean. By default, it is set to true. This setting shows the Low-Bandwidth notification button. Set it to false hide this button.
screenshot: Boolean. By default, it is set to true. This setting shows the Screeshot button. Set it to false hide this button.
avatar: Boolean. By default, it is set to true. This setting shows the avatar for No-Video stream. Set it to false hide this button.
iconColor: String. HEX color code for icons. The default value is #FFFFFF.
iconHeight: Number. Icon height in pixels. The default value is 30.
iconWidth: Number. Icon width in pixels. The default value is 30.
avatarHeight: Number. Avatar height in pixels. The default value is 200.
avatarWidth: Number. Avatar width in pixels. The default value is 200.
pinned: Boolean. By default, it is set to false. This setting hides the pinned user icon. Set it to false show this button.
advanceOptions advanceOptions.battery_updates Boolean Set to true to enable the Auto-Battery Updates feature.
advanceOptions.notify-video-resolution-change Boolean Set to true to enable the Video Resolution Change Notification feature.

Delegate Methods

MethodDescription
- room:didConnect:Acknowledgment to the client endpoint when it is connected to the room.
- room:didError:Acknowledgment of the client endpoint when it fails to connect to the room.
- room:userDidJoined:Notification to everyone in a room when a new user is connected to the room.
– room:didRoomAwaited:Notification to the client endpoint when it awaits the moderator's permission to enter a knock-enabled room or awaits the moderator to enter the room first in a wait-for-moderator enabled room.
The JSON structure of the event provides information on whether the room is knock-enabled { "event_type": "knock" } or wait-for-moderator enabled { "event_type": "wait_for_moderator" }

Sample Code

NSString *token = "XXX";
NSDictionary *roomInfo = { // Re-Connect Options
@"allow_reconnect": true,
@"number_of_attempts": 3,
@"timeout_interval": 10000,
@"audio_only": false
};
NSDictionary *advanceDict= @{
@"id":@"battery_updates",
@"enable":@YES
};
NSMutableArray *advanceOptionArray = [[NSMutableArray alloc] init];
[advanceOptionArray addObject:advanceDict];
advanceDict= @{
@"id":@"notify-video-resolution-change",
@"enable":@YES
};
[advanceOptionArray addObject:advanceDict];
// Initiates Room
EnxRoom *room = [[EnxRoom alloc] init];
// Connects with Re-Connection & Advance Options
[room connect:token roomInfo:roomInfo advanceOptions:advanveOptionArray ];
//Delegate methods
-(void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata{
// Connected. Delegate receives room instance and Room Meta JSON.
}
-(void)room:(EnxRoom *)room didError:(NSString *)reason{
// Connection failed. Find error
}
-(void)room:(EnxRoom *)room userDidJoined:(NSArray *)Data{
// A new user connected. user JSON has user information
}
-(void)room:(EnxRoom *)room didActiveTalkerList:(NSArray *)Data{
// List of talkers in the Room
// Received after room connected.
}

Error Codes and Exceptions

CodeDescription
5086Unable to connect to a room.

Join a Room with a Stream

A typical process to connect to a room involves the following steps:

  1. Initiate a room and connect to it.
  2. Initiate streaming after connecting, which requires you to check media accessibility.
  3. Publish a local stream.
  4. Check if the stream is successfully published.

To successfully join a room, you need to ensure the success of each step before proceeding to the next step, thus making it a complex process. The EnxRtc.joinRoom() method allows you to quickly join a room and get started without following every step of this procedure.

Class: EnxRtc

Method: -(EnxStream *)joinRoom:(NSString *)token delegate:(id)delegate PublishStreamInfo: (NSDictionary *)publishStreamInfo;

Parameters

ParameterData TypeDescription
tokenStringA JWT token to connect to the room. The token is received using the Server API call via the application server.
delegateJSON ObjectThe EnxRoomDelegate object is the delegate for the EnxRoom object .
publishStreamInfoStringOptional. For more information, see Stream Initialization Meta Info.

Returns: EnxStream JSON object containing the details of the published local stream.

Sample Code

NSDictionary* publishStreamInfo = {
video: true,
audio: true,
data: true,
attributes: { name: "XX" }
}
NSString* token = "XXX";
EnxRtc *enxRtc = [[EnxRtc alloc] init];
EnxStream *localStream = [enxRtc joinRoom:token delegate:self publishStreamInfo:publishStreamInfo];
//Delegate methods
-(void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata{
// Connected. Delegate receives room instance and Room Meta JSON.
}
-(void)room:(EnxRoom *)room didError:(NSString *)reason{
// Connection failed. Find error
}

Disconnect from a Room

The EnxRoom.disconnect() method closes the session and disconnects client endpoints from the eoom. The media and signaling sockets are also released in this process.

Class: EnxRoom

Method: - (void)disconnect;

Delegate Methods

MethodDescription
–room:didRoomDisconnect:Acknowledgment to the user when disconnected. The Callback allows you to update the UI of the user post disconnect.
–room:userDidDisconnected:Notification to everyone in the room when a user is disconnected. The callback allows you to update the UI of other connected users.

Sample Code

[room disconnect];
- (void)room:(EnxRoom *)room didRoomDisconnect:(NSArray * _Nullable)response {
// You are disconnected
}
-(void)room:(EnxRoom *)room userDidDisconnected:(NSArray *)Data{
// A user is disconnected
// Data - User Information of disconnected user
}

Error Codes and Exceptions

CodeDescription
5031Repeated disconnect() call made when the previous disconnection request is in process.
5032When the user tries to disconnect after getting disconnected from the room.

Handle Network Disconnection and Reconnection

A client endpoint is connected with EnableX over a secured web socket, which is susceptible to network failures. The client endpoint is notified of the failure through the following callbacks:

Delegate Methods

MethodDescription
- room:didConnectionLost:Notification to the client endpoint when the endpoint loses network connection.
- room:didConnectionInterrupted:Notification to the client endpoint when the connection is interrupted. For example, when the connection is switched from WiFi to 4G or vice versa.

Sample Code

- (void)room:(EnxRoom*)room didConnectionLost:(NSArray*)data {
// Disconnected. Handle UI
}
- (void)room:(EnxRoom*)room didConnectionInterrupted:(NSArray*)data{
// Interrupted. Handle UI
}

EnableX provides the Auto-Reconnection functionality for disconnected endpoints to ensure a better user experience. To use this feature, you must Connect to the Room with Reconnection options. Note that this feature is not applicable under the following circumstances:

  • The last participant has disconnected from the adhoc room.
  • The moderator has dropped the participant from the room.
  • The participant has explicitly disconnected from the room.

Delegate Methods

MethodDescription
- room:didUserReconnectSuccess:Notification to the user when a client endpoint is successfully reconnected with EnableX.
- room:didReconnect:Notification to the user when a Client endpoint attempts to reconnect within the specified time.

Sample Code

//To receive and handle reconnection events,
// you need to pass an argument called roomInfo (its is an optional parameter) while connecting to the room through the room api - joinRoom() or connect(). For example,
NSDictionary *roomInfo = {
@"allow_reconnect": true,
@"number_of_attempts": 3,
@"timeout_interval": 10000,
@"audio_only": false
};
//This will helps the end-point user to auto-reconnect to the same room.
NSDictionary *advanceDict= @{
@"id":@"battery_updates",
@"enable":@YES
};
NSMutableArray *advanceOptionArray = [[NSMutableArray alloc] init];
[advanceOptionArray addObject:advanceDict];
advanceDict= @{
@"id":@"notify-video-resolution-change",
@"enable":@YES
};
[advanceOptionArray addObject:advanceDict];
-(void)room:(EnxRoom*)room didUserReconnectSuccess:(NSDictionary*)data{
// Got reconnected
}
- (void)room:(EnxRoom *)room didReconnect:(NSString *)reason{
// Reconnecting
}

Error Codes and Exceptions

CodeDescription
5073Connection is switched to the current network .
5074Network is disconnected. The reconnection attempt has timed-out.
5086When a method is called when the room is not connected.
5087Reconnection has failed.

Video Quality Adaption based on Bandwidth

EnableX offers Automatic Bandwidth Detection (ABWD) to ensure optimum audio and video communication based on the available bandwidth at the client endpoint. The ABWD detects a change in the available bandwidth when it cannot continue to support all the videos that are received and notifies the client endpoint with the onRoomBandwidthAlert callback. You can handle this event by reducing the number of active talker videos received or by switching to the audio-only mode. It helps users facing extremely poor network conditions to switch to the audio-only mode without disrupting the session.

Delegate Method: -room:didRoomBandwidthAlert

Notification is sent to the affected client endpoint when:

  • Bandwidth at the endpoint reduces to a level where all the received videos cannot be supported.
  • Bandwidth at the endpoint increases to a level where more videos than those currently being received can be supported.

Notification is not triggered for any bandwidth fluctuation that does not affect the number of videos being received at the client endpoint.

Sample Code

// To receive notification
-(void)room:(EnxRoom *_Nullable)room didRoomBandwidthAlert:(NSArray *_Nullable)data;

-room:didRoomBandwidthAlert JSON Payload:

Object/KeyDescription
bandwidthUpdated (reduced or increased) bandwidth at the client endpoint.
number_of_videosNumber of videos that can be supported at the available bandwidth.

Sample Code

[
{ "bandwidth": 240,
"stream_bandwidth": 80,
"number_of_videos": 2
}
]