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:
- Initiate a room and connect to it.
- Initiate streaming after connecting, which requires you to check media accessibility.
- Publish local stream.
- 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
Parameter | Data Type | Description |
---|---|---|
token | String | This is an encoded token string received from the Enx application server. |
localInfo | String | This parameter is optional. For more information, see Stream Options to Initialize. |
roomInfo | String | Room information for joining a room. |
onRoomConnected | String | When the client endpoint successfully connected to the room. |
onRoomDisConnected | String | When the client endpoint gets disconnected from the room. |
onRoomError | String | When the client endpoint's attempt fails to connect to a room. |
onUserConnected | String | Everyone is notified that a new user is connected to the room. |
onUserDisConnected | String | Everyone is notified that a connected user is disconnected from the room. |
onConnectionLost | String | When the endpoint loses network connection. |
onConnectionInterrupted | String | When the connection is interrupted, e.g., Switch from WiFi to 4G and vice versa. |
onUserReconnectSuccess | String | When the endpoint gets successfully reconnected with EnableX. |
onReconnect | String | When the endpoint tries to reconnect within the given period. |
onPublishedStream | String | The publisher is notified that its stream has been published into the room. |
onUnPublishedStream | String | The 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 callingawait EnxRtc.joinRoom(token, localInfo, roomInfo, advanceOptions);//CallbacksEnxRtc.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 callbackEnxRtc.onRoomBandwidthAlert=(Map<dynamic,dynamic> map){};