Room Connection
The iOS SDK provides methods to initialise a room, connect to it, publish streams, and disconnect — including built-in automatic reconnection when network conditions change.
Initiate a Room
RTC sessions run in a virtual room hosted on EnableX. Start by initialising an
EnxRoom object. This is a purely local step — no network activity occurs until you
call connect().
- Method:
-(instancetype)init
EnxRoom *room = [[EnxRoom alloc] init];
Connect to a Room
The connect() method establishes a bi-directional web socket with the EnableX server
and joins the room using the provided JWT token.
- Method:
- (void)connect:(NSString *)token roomInfo:(NSDictionary *)roomInfo advanceOptions:(NSArray *)advanceOption
Parameters
| Parameter | Type | Description |
|---|---|---|
token |
String | JWT token received from the application server via the Video API. |
roomInfo Keys
| Key | Type | Description |
|---|---|---|
allow_reconnect |
Boolean | Default true. Enables auto-reconnection on network failure. Set false to disable. |
number_of_attempts |
Numeric | Max reconnection attempts. Default 3. Minimum 1. |
timeout_interval |
Numeric | Milliseconds to wait between reconnection attempts. |
activeviews |
String |
"list" — get individual streams to build your own view."view" — get a predefined video grid.
|
forceTurn |
Boolean | Default false. Set true to force all video through a TURN server. |
chat_only |
Boolean | Default false. Set true to enable text-chat only (disables audio/video). |
playerConfiguration |
Object |
Video player settings. Boolean keys: audiomute, videomute,
bandwidth, screenshot, avatar, pinned.
Color/size keys: iconColor (HEX), iconHeight,
iconWidth, avatarHeight, avatarWidth.
|
advanceOptions Keys
Pass advanceOptions as an NSArray of NSDictionary objects,
each with an "id" key and an "enable" boolean.
| Key | Type | Description |
|---|---|---|
battery_updates |
Boolean | Set true to enable auto battery status updates. |
notify-video-resolution-change |
Boolean | Set true to receive video resolution change notifications. |
Delegate Methods
| Delegate | Description |
|---|---|
-room:didConnect: |
Acknowledgment when connected to the room; includes room metadata. |
-room:didError: |
Acknowledgment when connection fails. |
-room:userDidJoined: |
Notification to all participants in the room when a new user connects. |
-room:didRoomAwaited: |
Notification when waiting for moderator approval in a knock-enabled room
(event_type: "knock") or a wait-for-moderator room
(event_type: "wait_for_moderator").
|
NSString *token = @"YOUR_JWT_TOKEN";
NSDictionary *roomInfo = @{
@"allow_reconnect" : @YES,
@"number_of_attempts": @3,
@"timeout_interval" : @10000,
@"activeviews" : @"list"
};
NSDictionary *batteryOption = @{ @"id": @"battery_updates", @"enable": @YES };
NSDictionary *resolutionOption = @{ @"id": @"notify-video-resolution-change", @"enable": @YES };
NSArray *advanceOptions = @[batteryOption, resolutionOption];
EnxRoom *room = [[EnxRoom alloc] init];
[room connect:token roomInfo:roomInfo advanceOptions:advanceOptions];
- (void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata {
// Connected — roomMetadata contains room details
}
- (void)room:(EnxRoom *)room didError:(NSString *)reason {
// Connection failed — inspect reason
}
- (void)room:(EnxRoom *)room userDidJoined:(NSArray *)data {
// A new user joined
}
- (void)room:(EnxRoom *)room didActiveTalkerList:(NSArray *)data {
// Active talker list received after connecting
}
Error codes: 5086 — unable to connect.
Join a Room with a Stream (Quick Connect)
EnxRtc.joinRoom() is a convenience method that handles room initialisation, stream
creation, and publishing in one call — removing the need to wire up each step manually.
- Class:
EnxRtc - Method:
-(EnxStream *)joinRoom:(NSString *)token delegate:(id)delegate PublishStreamInfo:(NSDictionary *)publishStreamInfo - Returns:
EnxStream— the published local stream object.
Parameters
| Parameter | Type | Description |
|---|---|---|
token |
String | JWT token from the application server. |
delegate |
Object | EnxRoomDelegate delegate. |
publishStreamInfo |
NSDictionary | Optional. Stream options: video, audio, data, attributes. |
NSDictionary *streamInfo = @{
@"video" : @YES,
@"audio" : @YES,
@"data" : @YES,
@"attributes": @{ @"name": @"User Name" }
};
EnxRtc *enxRtc = [[EnxRtc alloc] init];
EnxStream *localStream = [enxRtc joinRoom:@"YOUR_TOKEN"
delegate:self
PublishStreamInfo:streamInfo];
- (void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata {
// Connected
}
- (void)room:(EnxRoom *)room didError:(NSString *)reason {
// Connection failed
}
Disconnect from a Room
Call disconnect to close the session and release all media and signaling sockets.
Other participants in the room receive a notification that you have left.
- Method:
- (void)disconnect
Delegate Methods
| Delegate | Description |
|---|---|
-room:didRoomDisconnect: |
Acknowledgment to the user when they disconnect. |
-room:userDidDisconnected: |
Notification to everyone in the room when a user disconnects. |
[room disconnect];
- (void)room:(EnxRoom *)room didRoomDisconnect:(NSArray *)response {
// You are disconnected
}
- (void)room:(EnxRoom *)room userDidDisconnected:(NSArray *)data {
// A user disconnected — data contains their information
}
Error codes: 5031 — repeated disconnect in progress; 5032 — already disconnected.
Client endpoints connect over a secured web socket. If the network fails, EnableX can automatically attempt to reconnect.
Network Failure Events
Delegate Methods
| Delegate | Description |
|---|---|
-room:didConnectionLost: |
Notified when the network connection is lost. |
-room:didConnectionInterrupted: |
Notified when the connection is interrupted (e.g., WiFi to 4G switch). |
- (void)room:(EnxRoom *)room didConnectionLost:(NSArray *)data {
// Connection lost — update UI
}
- (void)room:(EnxRoom *)room didConnectionInterrupted:(NSArray *)data {
// Connection interrupted — update UI
}
Reconnection Events
Enable auto-reconnection by passing allow_reconnect: YES in the roomInfo
to connect().
Delegate Methods
| Delegate | Description |
|---|---|
-room:didUserReconnectSuccess: |
Notified when the endpoint successfully reconnects. |
-room:didReconnect: |
Notified when a reconnection attempt is in progress. |
- (void)room:(EnxRoom *)room didUserReconnectSuccess:(NSDictionary *)data {
// Successfully reconnected
}
- (void)room:(EnxRoom *)room didReconnect:(NSString *)reason {
// Reconnection attempt underway
}
Error codes: 5073 — switched to current network; 5074 — reconnection timed out; 5086 — method called on disconnected room; 5087 — reconnection failed.
Bandwidth Alert
EnableX includes Automatic Bandwidth Detection (ABWD) that monitors the client's available bandwidth. When bandwidth drops too low to support all received video streams, or recovers to support more, all affected endpoints are notified.
Delegate: -room:didRoomBandwidthAlert:
The notification is not triggered for every bandwidth fluctuation — only when the change affects the number of videos that can be received.
Payload Fields
| Field | Description |
|---|---|
bandwidth |
Updated bandwidth level at the client endpoint. |
stream_bandwidth |
Per-stream bandwidth. |
number_of_videos |
Number of videos that can be supported at current bandwidth. |
- (void)room:(EnxRoom *)room didRoomBandwidthAlert:(NSArray *)data {
// Respond by reducing active talkers or switching to audio-only mode
// data: [{ "bandwidth": 240, "stream_bandwidth": 80, "number_of_videos": 2 }]
}