Skip to main content
Version: 5.x.x

Room Connection Events - Flutter

VideoSDK provides Events.roomStateChanged event which will notify you of the current connection state of the room.

Events.roomStateChanged​

  • This event is triggered whenever the room's state changes.
  • The current state of the room is passed as a callback parameter.
  • All available states are RoomState.CONNECTING, RoomState.CONNECTED, RoomState.DISCONNECTED, RoomState.RECONNECTING and RoomState.FAILED. FAILED means the connection failed and will not be retried.
  • The latest state is also on room.roomState.
  • While the state is RECONNECTING, room actions are refused with error 3065.
  • It can be subscribed to using the Room object.

Example​

Here is the usage of the event mentioned in this page.

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.roomStateChanged, (RoomState state) {
switch (state) {
case RoomState.CONNECTING:
print('Room is Connecting');
break;
case RoomState.CONNECTED:
print('Room is Connected');
break;
case RoomState.DISCONNECTED:
print('Room is Disconnected');
break;
case RoomState.RECONNECTING:
print('Room in reconnecting state');
break;
case RoomState.FAILED:
print('Room connection failed');
break;
}
});
}
}

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