Basic Functions of Flutter SDK describes the necessary tasks to achieve basic Audio/Video communication between participants connected from their End-Point Applications to an EnableX hosted Room. For more advanced use cases, please refer Advance Features & Moderator Controls.

Table of Contents

Get list of Audio & Video Devices

You will need to specify Audio/Video Device ID (Microphone & Camera Device ID) or use the default Microphone Device ID of your Mobility Device to initiate a Stream. EnableX provides API support to get a list of Audio Devices (Microphone) available with your Device running the Client End Point application along with their device IDs.

The getDevices() method is used to return a List containing all the Microphones available with your Device. You can build UI Element with the List to choose a Microphone to use for Stream.

Method: public List <String> getDevices() – No parameter needed

List<dynamic> deviceList= EnxRtc.getDevices();
// Returns [SPEAKER_PHONE, WIRED_HEADSET, EARPIECE, BLUETOOTH, NONE ]

Get selected Audio Device by User

EnxRoom.getSelectedDevice() method is used to get the selected or used Audio Device for the Stream.

Method: static Future<String> getSelectedDevice() – No parameter needed

String deviceName = EnxRtc.getSelectedDevice();

Join a Room with Stream

Connecting and joining a Room is a complex chain of events. You will need to ensure success status of previous event to proceed to the next event. The following basic steps are required to join room successfully

  • Initiate Room & Connect
  • If connected, initiate Stream.
  • Publish Stream

joinRoom() method comes as a handy tool for developer. It handles all complexities of connecting and joining the room.

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

Parameters:

  • @param String token – JWT Token received through Server API Call
  • @param Map<String,dynamic> locfoStream Initialization Meta Info. Optional.
  • @param Map<String,dynamic> roomInfo – Room info for joining room

Event Listeners:

  • onRoomConnected – When Client End Point is connected to the room successfully
  • onRoomDisConnected – Client End Point got disconnected to the room
  • onRoomError – Client End Point’s attempt to connect to room has failed
  • onUserConnected – Everyone is notified that a new user is connected to the Room
  • onUserDisConnected – Everyone is notified that a connected user is disconnected from the Room
  • onConnectionLost – When End Point looses network connection
  • onConnectionInterrupted – When connection is interrupted e.g Switch from WiFi to 4G and vice versa
  • onUserReconnectSuccess – When End-Point successfully gets reconnected with EnableX
  • onReconnect – When End-Point trying to reconnect within given time period.
  • onPublishedStream – Publisher is notified that its Stream has been published into the Room
  • onUnPublishedStream – Publisher is notified that its Stream is unpublished/removed from the Room.
//Map<String, dynamic>: where localInfo is like below:
Map<String, dynamic> videoSize = {
	'minWidth': 320,
	'minHeight': 180,
	'maxWidth': 1280,
	'maxHeight': 720
};

Map<String, dynamic> localInfo= {
	'audio': true,
	'video': true,
	'data': true,
	'framerate': 30,
	'maxVideoBW': 1500,
	'minVideoBW': 150,
	'audioMuted': false,
	'videoMuted': false,
	'name': 'flutter',
	'videoSize': videoSize
};

//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 End Point can disconnect itself from the room to close its session. A disconnected End-Point will loose media and signaling socket immediately.

Method: static Future<void> disconnect() – Without any parameter

EnxFlutterSDK.disconnect();

Publish / Unpublish Local Stream

The local stream with audio/video needs to be started and published to the Room for other participants to see and hear you. Please use the API methods below to publish, unpublish and close local stream.

Publish Local Stream

publish() method is used to publish a local stream to the connected Room. After the local stream is published to the Room, all participants are notified with an eent listener  onPublishedStream.

Method: static Future<void> publish()

Event Listener::

  • onPublishedStream – To the publisher that stream has been published.
EnxRtc.onRoomConnected = (Map<dynamic, dynamic> map) { 
	//Method calling   
	EnxRtc.publish();
};

EnxRtc.onPublishedStream = (Map<dynamic, dynamic> map) {
};

Unpublish Local Stream

To receive media streams of other participants connected to a Room, you must subscribe to the streams individually. Unless you subscribe a stream, you will not receive anything.

To unpublish, use unpublish() method. Please use the callback to handle if stream is unpublished successfully. All users connected to the room will be notified that a Published Stream is unpublished or removed from the Room using the callback named onSubscribeStream

Method: static Future<void> subscribe(String streamId)

Parameters:

  • @param String streamId – Stream id to subscribe.

Event Listener:: onSubscribeStream- to all participants that a Stream is taken off the Room.

EnxRtc.onStreamAdded = (Map<dynamic, dynamic> map) {
	String streamId;
	setState(() {
		streamId = map['streamId'];
	});
	EnxRtc.subscribe(streamId);
};

EnxRtc.onSubscribedStream= (Map<dynamic, dynamic> map) {    
};

Subscribe Remote Streams

To receive media streams of other participants connected to a Room, you must subscribe to the streams individually. Unless you subscribe a stream, you will not receive anything.

Method: static Future<void> subscribe(String streamId)

Parameters:

  • @param String streamId – Stream id to subscribe.

Event Listener:: onSubscribeStream- to all participants that a Stream is taken off the Room.

EnxRtc.onStreamAdded = (Map<dynamic, dynamic> map) {
	String streamId;
	setState(() {
		streamId = map['streamId'];
	});
	EnxRtc.subscribe(streamId);
};

EnxRtc.onSubscribedStream= (Map<dynamic, dynamic> map) {    
};

Mute / Unmute Audio of Subscribed Streams

To mute / unmute Audio of Subscribed Streams, use muteSubscriberStreamsAudio() method.

Method: static Future<void> muteSubscriberStreamsAudio(bool isMute)

Parameters:

  • @param bool isMute – Set true to mute, false to unmute.
EnxRtc.muteSubscriberStreamsAudio(true); // To mute
EnxRtc.muteSubscriberStreamsAudio(false); // To unmute

Handle Active Talkers

Get maximum permissible Talker Count

To know maximum permissible Active Talkers that you may receive and you can set, you may use getMaxTalkers() method.

Method: static Future<void> getMaxTalkers() – without parameter

Event Listener: onMaxTalkerCount – Gets maximum talker allowed in the room

EnxRtc.getMaxTalkers();

EnxRtc.onMaxTalkerCount= (Map<dynamic, dynamic> map) {
     // Talker info in response JSONObject
     // {"result": 0, "maxTalkers": 4} 
}

Get Talker Count

It may be necessary to know how many talkers are expected to receive with  onActiveTalkerList Event Listener, i.e. to know either the preset value of talkers or any custom value in effect which is either by the Application Developer or opted by End-Point User.

Method: static Future<void> getTalkerCount() – without parameter

Event Listener: onGetTalkerCount – Gets Talker count

EnxRtc.getTalkerCount();

EnxRtc.onGetTalkerCount = (Map<dynamic, dynamic> map) {
     // Talker info in response JSONObject
     // {"result": 0, "maxTalkers": 4} 
}

Set Talker Count

EnableX sets a maximum of 6 active talkers in the active talker-list with  onActiveTalkerList Active Talkers. However, you may opt to receive less talkers at a Client End Point if you so require. This may either be a predefined value, or this value may be set at run-time in a connected session. If needed, you can create UI for the connected user to opt for number of active-talkers the user wants to receive.

Method: Future<void> setTalkerCount(int count)

Parameters@param int count – No. of talkers you want to receive. Range 0-6

  • If you set count to any value from 1 to 6 – you will receive those many talkers in the list.
  • If you set count to 0 (zero), then list doesn’t become empty. Rather, you would start receiving 3 audio streams only. Video Streams will not be carried.

Event Listener: onSetTalkerCount

EnxRtc.setTalkerCount(2);

EnxRtc.onSetTalkerCount = (Map <dynamic, dynamic> map) {
	// Talker info in response jsonobject:
	// {"result": 0, "maxTalkers": 4}
}

Know Room Information

EnableX API provides different methods to access Room Information.

Get Room ID

Every Room is assigned with a Unique Room ID while creating the Room. The Room ID of the room to which you are connected may be known by using getRoomId() method.

Method: static Future<String> getRoomId() – No parameter needed

String room_id = EnxRtc.getRoomId();

Get connected User ID or Client ID

Each connected user to the Room is assigned with a Unique Client ID for the session. To know the Client ID of the connected user from the enc-point, use getClientId() method.

Method: static Future<String> getClientId() – No parameter needed

String ClientId = EnxRtc.getClientId(); 

Get connected User Name

To know the name of connected user from the end-point, use getClientName() method.

Method: static Future<String> getClientName() – No parameter needed

String ClientName = EnxRtc.getClientName(); 

Get connected User Role

A User connected to a Room with either role of moderator or participant. Use getRole() to know role of the user

Method: static Future<String> getRole() – No parameter needed

Returns: Enumerated Values: moderator, participant

String role = EnxRtc.getRole();

Get connected User Information at an End-Point

To get connected user information at an End-Point, use whoami() method. It returns complete user-meta for the connected user in a JSON Object.

Method: static Future<Map<String, dynamic>> whoAmI() – No parameter needed

JSONObject myinfo = EnxRtc.whoami(); 

Note: Refer JSON Object structure for User Meta – i.e. for myinfo in above example.

Get connected User List

To get a list of connected users to the Room to which the enc-point is also connected to, use getUserList() method. It returns a JSON with list of connected user’s information.

Method: static Future<List<dynamic>> getUserList() – No parameter needed

List users= EnxRtc.getUserList();

// Return List Users
/*
[
      {
          "clientId": "",             // Unique Client ID assigned by EnableX
          "name": "",                 // User's name
          "user_ref": "",             // User's Reference
          "role": "participant",      // Enum: moderator, participant
          "permissions": {            // In-Session Permission of User
          "publish": Boolean,         // Whether user can pubish local stream
          "subscribe": Boolean,       // Whether user can subscribe remote streams
          "record": Boolean,          // Whether user can initiate recording
          "stats": Boolean,           // Whether user can view stream status
          "controlhandlers": Boolean  
          }
      }
  ] 
*/

Get list of Remote Streams

To get all the Remote Streams available in the Room, use getRemoteStreams() method.

Method: public Map < String, EnxStream > getRemoteStreams() – No parameter needed

Map <String, EnxStream> remoteStreams = room.getRemoteStreams();

Know if Room has Active Talker

To check if the Room has Active Talker use isRoomActiveTalker() method.

Method: static Future<bool> isRoomActiveTalker()

await EnxRtc.isRoomActiveTalker();

Manage Logging

The Web SDK writes different type of logs to the browser console to  help in debugging at development phase. EnableX provides two methods to access and control these log entries.

Enable Log

The IO Operations to write log may be a considerably time consuming task. Therefore, you may like to have control to enable or disable logging.

Method: static Future<void> enableLogs(bool status)

Parameter: bool status – Set true to enable and false to disable logging

EnxRtc.enableLogs(true);	// To enable logging
EnxRtc.enableLogs(false);	// To disable logging

Share Log with EnableX to audit

To share console logs with EnableX Tech Team use the available method in SDK. The method sends latest 500 lines of console log to EnableX using HTTP Post. You may need to build your own UI around it. Please request for  user’s consent before you post log to EnableX.

You must enable logging before you can share it.

Method: static Future<void> postClientLogs()

EnxRtc.postClientLogs();	// To post log to audit

Explore Flutter SDK