OpenVidu Flutter client.
First, add the openvidu_client
package to your pubspec dependencies.
To import OpenViduClient
:
import 'package:openvidu_client/openvidu_client.dart';
To use OpenViduClient
create a instance with the URL of the OpenVidu Server:
client = OpenViduClient('https://demos.openvidu.io/openvidu');
Start the local preview, and return the local participant
localParticipant = await _openvidu.startLocalPreview(context, StreamMode.frontCamera);
Config listener to the events that are emitted by the OpenVidu library; remember subscribe remotes inside OpenViduEvent.userJoined and OpenViduEvent.userPublished.
void listenSessionEvents() {
client.on(OpenViduEvent.userJoined, (params) async {
await client.subscribeRemoteStream(params["id"]);
});
client.on(OpenViduEvent.userPublished, (params) {
await client.subscribeRemoteStream(params["id"],
video: params["videoActive"], audio: params["audioActive"]);
});
client.on(OpenViduEvent.addStream, (params) {
remoteParticipants = {...client.participants};
//Catch changes on remote participant
});
client.on(OpenViduEvent.removeStream, (params) {
remoteParticipants = {...client.participants};
//Catch changes on remote participant
});
client.on(OpenViduEvent.publishVideo, (params) {
remoteParticipants = {...client.participants};
//Catch changes on remote participant
});
client.on(OpenViduEvent.publishAudio, (params) {
//Catch changes on remote participant
});
client.on(OpenViduEvent.updatedLocal, (params) {
localParticipant = params['localParticipant'];
//Update the local participant
});
client.on(OpenViduEvent.reciveMessage, (params) {
//Capture message received
});
client.on(OpenViduEvent.userUnpublished, (params) {
remoteParticipants = {...client.participants};
//Catch changes on remote participant
});
client.on(OpenViduEvent.error, (params) {
//Capture error messages
});
}
It joins to the room, and returns the local participant
- token (String): The token you get from the server.
- userName (String): The name of the user who is publishing the stream.
- extraData (Map<String, dynamic>): Extra data to be sent to the server.
It changes the stream mode from camera to screen and vice versa.
Replace the track with the new track by deviceId
Switches the camera to the deviceId passed in
Can switch between cameras
It disables all the tracks of the local stream
It enables or disables the video track of the local stream
Enable or disable the audio track of the stream, depending on the value of the parameter