Room Connection

The Flutter SDK provides the following methods:

  • joinRoom(): To join a room quickly.
  • disconnect(): To close the session and disconnect the client endpoint from the room.

Join a Room with a Stream

The typical process to connect to a room is as follows:

  1. Initiate a room and connect to it.
  2. Initiate streaming after connecting, which requires you to check media accessibility.
  3. Publish 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, thus making it a complex process.

The EnxRtc.joinRoom() method allows you to quickly join a room and get started without following the above procedure step by step.

Class: EnxRtc

Method: static Future<void> joinRoom(String token, Map<String, dynamic> localInfo, Map<String, dynamic> roomInfo, List<dynamic> advanceOptions)

Parameters

ParameterData TypeDescription
tokenStringThis is an encoded token string received from the Enx application server.
localInfoStringThis parameter is optional. For more information, see Stream Options to Initialize.
roomInfoStringRoom information for joining a room.
onRoomConnectedStringWhen the client endpoint successfully connected to the room.
onRoomDisConnectedStringWhen the client endpoint gets disconnected from the room.
onRoomErrorStringWhen the client endpoint's attempt fails to connect to a room.
onUserConnectedStringEveryone is notified that a new user is connected to the room.
onUserDisConnectedStringEveryone is notified that a connected user is disconnected from the room.
onConnectionLostStringWhen the endpoint loses network connection.
onConnectionInterruptedStringWhen the connection is interrupted, e.g., Switch from WiFi to 4G and vice versa.
onUserReconnectSuccessStringWhen the endpoint gets successfully reconnected with EnableX.
onReconnectStringWhen the endpoint tries to reconnect within the given period.
onPublishedStreamStringThe publisher is notified that its stream has been published into the room.
onUnPublishedStreamStringThe publisher is notified that its stream is unpublished/removed from the room.

Sample Code

//Map<String, dynamic>: where localInfo is like below:
Map<String, dynamic> localInfo= {
'audio': true,
'video': true,
'data': true,
'audioMuted': false,
'videoMuted': false,
'name': 'flutter',
};
//Map<String, dynamic>: where roomInfo is like below:
Map<String, dynamic> roomInfo = {
'allow_reconnect': true,
'number_of_attempts': 3,
'timeout_interval': 20,
'audio_only': false,
'forceTurn': false
};
//Method calling
await EnxRtc.joinRoom(token, localInfo, roomInfo, advanceOptions);
//Callbacks
EnxRtc.onRoomConnected = (Map<dynamic, dynamic> map) {
//Connection success
};
EnxRtc.onRoomError = (Map<dynamic, dynamic> map) {
// Connection Failed or any error in room
};
EnxRtc.onRoomDisConnected = (Map<dynamic, dynamic> map) {
// Called when room is disconnected success
};
EnxRtc.onConnectionLost = (Map<dynamic, dynamic> map) {
// In case connection lost due to internet lose
};
EnxRtc.onConnectionInterrupted = (Map<dynamic, dynamic> map) {
// In case any interruption in connection
};
EnxRtc.onUserReconnectSuccess = (Map<dynamic, dynamic> map) {
// When reconnect done successfully
};
EnxRtc.onReconnect = (Map<dynamic, dynamic> map) {
};

Disconnect from a room

A client endpoint can disconnect itself from the room to close its session. A disconnected endpoint will lose media and signaling socket immediately.

Class: EnxRtc

Method: static Flutter<void> disconnect()

Sample Code

EnxRtc.disconnect();

Video Quality Adaption based on Bandwidth

EnableX offers Automatic Bandwidth Detection (ABWD) to ensure optimum audio or 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 being received and notifies the client endpoint with callback onRoomBandwidthAlert. You can handle this event by reducing the number of Active Talker videos received or switching to audio-only mode.

It helps users facing deplorable network conditions to go into audio-only mode without disrupting the session.

Callback: onRoomBandwidthAlert

  • Notification is sent to the affected client endpoint when:

    • Bandwidth at the endpoint reduces to a level where all videos being received 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 callback
EnxRtc.onRoomBandwidthAlert=(Map<dynamic,dynamic> map){
};