Handle a Local Stream

The Flutter SDK provides the following methods to handle a local stream:

Publish a Local Stream

It is important to publish your media stream into the room for other connected users to see and communicate with you. You can continue publishing your stream until you exit, or unpublish and republish your media stream multiple times within the same session if required.

After initializing the stream, you need to publish it in the room so that other users in the room can see and hear the user on this stream.

The publish() method publishes a local stream to the connected room. After the local stream is published to the room, all participants are notified by an event listener onPublishedStream.

Class: EnxRtc

Method: static Future<void> publish()

Event Listener Name: onPublishedStream: To the publisher, that stream has been published.

Sample Code

EnxRtc.onRoomConnected = (Map<dynamic, dynamic> map) {
//Method calling
EnxRtc.publish();
};
EnxRtc.onPublishedStream = (Map<dynamic, dynamic> map) {
};

Unpublish a Local Stream

To receive media streams of other participants connected to a room, you must subscribe to the streams individually. You will not receive a stream unless you subscribe to it.

The unpublish() method disconnects the local stream from the room. Please use the callback to handle if the stream is unpublished successfully. All users connected to the room will be notified that a published stream is unpublished from the room using the onSubscribeStream callback.

Class: EnxRtc

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

Parameter: streamId : String. The Stream ID to subscribe.

Event Listener: onSubscribeStream: JSOnObject. Notification to all participants that a stream is unpublished from the room.

Sample Code

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

Switch to Source Media Devices of Published Streams

Users can switch to alternate media devices for their published stream. EnableX API allows media device switching on the fly.

The EnxRtc.switchMediaDevice() method allows you to switch between the rear and front camera and to switch microphones.

Class: EnxRtc

Method: static Future<void> switchMediaDevice(String deviceName)

Parameters

ParameterData TypeDescription
deviceNameStringThe device name as received from the getDevices() API.
onNotifyDeviceUpdateJSOnObjectWhen the audio device change is complete.

Sample Code

EnxRtc.switchMediaDevice('deviceName'); // Switch to new Device
// Listen when Device has been switched
EnxRtc.onNotifyDeviceUpdate = (String deviceName) {
};

Switch Between Rear and Front Camera

The EnxStream.switchCamera() method allows you to switch between the rear and the front camera as a source for published stream.

Class: EnxRtc

Method: static Future<void> switchCamera()

Sample Code

EnxRtc.switchCamera();

Mute or Unmute Audio in a Stream

The EnxRtc.muteSelfAudio() method is used to mute and unmute audio of your local stream. The event onAudioEvent notifies the user when self audio is muted/unmuted. All other connected users in the room are notified with The onRemoteStreamAudioMute and onRemoteStreamAudioUnMute event listeners, when a user mutes or unmutes audio from the published stream respectively. Listen to these events to update related UI elements.

Class: EnxRtc

Methods: static Future<void> muteSelfAudio(bool isMute)

Parameter

ParametersData TypeDescription
isMuteBooleanSet it to true to mute audio; Set it to false to unmute audio.
onRemoteStreamAudioMuteJSON ObjectNotification to everyone in the room when a user mutes self audio.
onRemoteStreamAudioUnMuteJSON ObjectNotification to everyone in the room when a user unmutes self audio.
onAudioEventJSON ObjectAcknowledgment to the user when self audio is muted/unmuted.

Sample Code

EnxRtc.muteSelfAudio(true); // Muting Audio
EnxRtc.onAudioEvent = (Map<dynamic,dynamic> map) {
};
EnxRtc.onRemoteStreamAudioMute=(Map<dynamic,dynamic> map) {
};
EnxRtc.onRemoteStreamAudioUnMute=(Map<dynamic,dynamic> map) {
};

Mute or Unmute Video in a Stream

The EnxRtc.muteSelfVideo() method is used to mute and unmute audio of your local stream. The event onVideoEvent notifies the user when self audio is muted/unmuted. All other connected users in the room are notified with The onRemoteStreamVideoMute and onRemoteStreamVideoUnMute event listeners, when a user mutes or unmutes video from the published stream respectively.

Class: EnxRtc

Methods: static Future<void> muteSelfVideo(bool isMute)

Parameters

ParameterData TypeDescription
isMuteBooleanSet it to true to mute video; Set it to false to unmute video.
onRemoteStreamVideoMuteJSON ObjectNotification to everyone in the room when a user mutes self video.
onRemoteStreamVideoUnMuteJSON ObjectNotification to everyone in the room when a user unmutes self video.
onVideoEventJSON ObjectAcknowledgment to the user when self video is muted/unmuted.

Sample Code

EnxRtc.muteSelfVideo(true); // Muting Video
EnxRtc.onVideoEvent = (Map<dynamic,dynamic> map) {
};
EnxRtc.onRemoteStreamVideoMute=(Map<dynamic,dynamic> map) {
};
EnxRtc.onRemoteStreamVideoUnMute=(Map<dynamic,dynamic> map) {
};

Update Stream Configuration

The EnxStream.updateConfiguration() method updates the parameters of a stream when you re-configure your stream by adding new or updating existing specification parameters of a stream. Both remote and local streams can use this method of updating the stream parameters.

Class: EnxRtc

Method: static Future<void>updateConfiguration(Map<String, dynamic> config)

Parameters: config: Map containing new configuration options

Sample Code

Map<String, dynamic> mapConfig = {
'maxVideoBW': 150,
'minVideoBW': 150,
'maxAudioBW': 150,
'minAudioBW': 150
};
EnxRtc.updateConfiguration(mapConfig);