Skip to main content
Version: 5.x.x

Media Events - Flutter

VideoSDK offers various events that can be monitored to obtain information about the media status of participants in the room.

Here are the events specifically related to the stream:

Events.streamEnabled​

  • This event is triggered whenever a participant's video, audio or screen share stream is enabled, including your own.
  • It can be subscribed to using the Room object.
  • The handler receives the RTCStream. stream.participantId is the id of the participant the stream belongs to, and stream.kind is a MediaType.

Events.streamDisabled​

  • This event is triggered whenever a participant's video, audio or screen share stream is disabled, including your own.
  • It can be subscribed to using the Room object.
  • The handler receives the RTCStream. stream.participantId is the id of the participant the stream belongs to, and stream.kind is a MediaType.

Events.streamPaused​

  • This event is triggered whenever a video, audio or screen share stream you receive is paused.
  • It can be subscribed to using the Room object.
  • The handler receives the stream's kind (audio, video or share) and the reason, both as String?. The room's handler does not say which participant's stream was paused; a handler added with participant.on() gets only that participant's streams.

Events.streamResumed​

  • This event is triggered whenever a paused stream you receive is resumed.
  • It can be subscribed to using the Room object.
  • The handler receives the stream's kind and the reason, both as String?. The room's handler does not say which participant's stream was resumed; a handler added with participant.on() gets only that participant's streams.
note

Each of these events is also delivered on the participant who owns the stream. Listen with participant.on() in a participant tile.

Example​

Here is an example demonstrating the usage of all the events mentioned on this page.

A participant tile listens for its participant's streams on the room. Streams that already exist when the tile is built are in participant.streams.

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class ParticipantTile extends StatefulWidget {
final Room room;
final Participant participant;
//Existing configuration
}

class _ParticipantTileState extends State<ParticipantTile> {
@override
void initState() {
super.initState();
//Existing configuration

setupRoomEventListener();
}

@override
Widget build(BuildContext context) {
return YourParticipantTileWidget();
}

void setupRoomEventListener() {
widget.room.on(Events.streamEnabled, _onStreamEnabled);
widget.room.on(Events.streamDisabled, _onStreamDisabled);
}

void _onStreamEnabled(RTCStream stream) {
// The room reports every participant's streams, so keep only this one's
if (stream.participantId != widget.participant.id) return;

if (stream.kind == MediaType.VIDEO) {
// Participant turned on video
} else if (stream.kind == MediaType.AUDIO) {
// Participant turned on audio
} else if (stream.kind == MediaType.SHARE) {
// Participant started screenshare
}
}

void _onStreamDisabled(RTCStream stream) {
if (stream.participantId != widget.participant.id) return;

if (stream.kind == MediaType.VIDEO) {
// Participant turned off video
} else if (stream.kind == MediaType.AUDIO) {
// Participant turned off audio
} else if (stream.kind == MediaType.SHARE) {
// Participant stopped screenshare
}
}

@override
void dispose() {
// The room outlives the tile, so remove the handlers from it
widget.room.off(Events.streamEnabled, _onStreamEnabled);
widget.room.off(Events.streamDisabled, _onStreamDisabled);
super.dispose();
}
}

On the room, streamPaused and streamResumed do not say whose stream it was. Listen for them on the room to react to any pause, or with participant.on() in a tile.

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class RoomScreen extends StatefulWidget {
//Existing configuration
}

class _RoomScreenState extends State<RoomScreen> {
late Room room;

@override
void initState() {
super.initState();
//Existing configuration

setupRoomEventListener();
}

@override
Widget build(BuildContext context) {
return YourRoomWidget();
}

void setupRoomEventListener() {
room.on(Events.streamPaused, (String? kind, String? reason) {
if (kind == "video") {
// A video stream you receive was paused
} else if (kind == "audio") {
// An audio stream you receive was paused
} else if (kind == "share") {
// A screenshare stream you receive was paused
}
});

room.on(Events.streamResumed, (String? kind, String? reason) {
if (kind == "video") {
// A video stream you receive was resumed
} else if (kind == "audio") {
// An audio stream you receive was resumed
} else if (kind == "share") {
// A screenshare stream you receive was resumed
}
});
}
}

Stream state​

Each RTCStream also reports whether it is active, stuck or frozen. Listen with stream.on(Events.streamStateChanged, (StreamState state, int timestamp) {}). See Stream Events.

API Reference​

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord