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.

Initialising and Connecting

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().

// Delegate assigned at init
let room = EnxRoom(self)

// Or create without delegate and assign before connect()
let room = EnxRoom()
room.connect(token, roomInfo: nil, advanceOptions: nil)

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.

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").
let token = "YOUR_JWT_TOKEN"

let roomInfo: [String: Any] = [
    "allow_reconnect"   : true,
    "number_of_attempts": 3,
    "timeout_interval"  : 10000,
    "activeviews"       : "list"
]

let batteryOption:    [String: Any] = ["id": "battery_updates",                "enable": true]
let resolutionOption: [String: Any] = ["id": "notify-video-resolution-change", "enable": true]
let advanceOptions = [batteryOption, resolutionOption]

let room = EnxRoom(self)
room.connect(token, roomInfo: roomInfo, advanceOptions: advanceOptions)

func room(_ room: EnxRoom?, didConnect roomMetadata: [String: Any]?) {
    // Connected — roomMetadata contains room details
}

func room(_ room: EnxRoom?, didError reason: [Any]?) {
    // Connection failed — inspect reason
}

func room(_ room: EnxRoom?, userDidJoined data: [Any]?) {
    // A new user joined
}

func room(_ room: EnxRoom?, didActiveTalkerList data: [Any]?) {
    // 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.

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.
let streamInfo: [String: Any] = [
    "video"     : true,
    "audio"     : true,
    "data"      : true,
    "attributes": ["name": "User Name"]
]

let enxRtc = EnxRtc()
let localStream = enxRtc.joinRoom(
    "YOUR_TOKEN",
    delegate: self,
    publishStreamInfo: streamInfo,
    roomInfo: nil,
    advanceOptions: nil
)

func room(_ room: EnxRoom?, didConnect roomMetadata: [String: Any]?) {
    // Connected
}

func room(_ room: EnxRoom?, didError reason: [Any]?) {
    // Connection failed
}
Disconnecting

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.

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()

func room(_ room: EnxRoom?, didRoomDisconnect response: [Any]?) {
    // You are disconnected
}

func room(_ room: EnxRoom?, userDidDisconnected data: [Any]?) {
    // A user disconnected — data contains their information
}

Error codes: 5031 — repeated disconnect in progress; 5032 — already disconnected.

Network Reconnection

Client endpoints connect over a secured web socket. If the network fails, EnableX can automatically attempt to reconnect.

Auto-reconnection is not triggered when: the last participant disconnects from an adhoc room, the moderator drops the participant, or the participant explicitly disconnects.

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).
func room(_ room: EnxRoom?, didConnectionLost data: [Any]?) {
    // Connection lost — update UI
}

func room(_ room: EnxRoom?, didConnectionInterrupted data: [Any]?) {
    // 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.
func room(_ room: EnxRoom?, didUserReconnectSuccess data: [String: Any]?) {
    // Successfully reconnected
}

func room(_ room: EnxRoom?, didReconnect reason: String?) {
    // Reconnection attempt underway
}

Error codes: 5073 — switched to current network; 5074 — reconnection timed out; 5086 — method called on disconnected room; 5087 — reconnection failed.

Bandwidth Adaptation

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.
func room(_ room: EnxRoom?, didRoomBandwidthAlert data: [Any]?) {
    // Respond by reducing active talkers or switching to audio-only mode
    // data: [{ "bandwidth": 240, "stream_bandwidth": 80, "number_of_videos": 2 }]
}