updated README with new event system
This commit is contained in:
@@ -122,8 +122,8 @@ Audio tracks are rendered automatically as long as you are subscribed to them.
|
|||||||
|
|
||||||
LiveKit client makes it simple to build declarative UI that reacts to state changes. It notifies changes in two ways
|
LiveKit client makes it simple to build declarative UI that reacts to state changes. It notifies changes in two ways
|
||||||
|
|
||||||
* `ChangeNotifier` - generic notification of changes
|
* `ChangeNotifier` - generic notification of changes. This is useful when you are building reactive UI and only care about changes that may impact rendering.
|
||||||
* `RoomDelegate` and `ParticipantDelegate` - notification of specific events.
|
* `EventsListener<Event>` - listener pattern to listen to specific events (see [events.dart](https://github.com/livekit/client-sdk-flutter/blob/main/lib/src/events.dart)).
|
||||||
|
|
||||||
This example will show you how to use both to react to room events.
|
This example will show you how to use both to react to room events.
|
||||||
|
|
||||||
@@ -139,17 +139,30 @@ class RoomWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RoomState extends State<RoomWidget> with RoomDelegate {
|
class _RoomState extends State<RoomWidget> {
|
||||||
|
late final EventsListener<RoomEvent> _listener = widget.room.createListener();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
widget.room.delegate = this;
|
// used for generic change updates
|
||||||
widget.room.addListener(_onChange);
|
widget.room.addListener(_onChange);
|
||||||
|
|
||||||
|
// used for specific events
|
||||||
|
_listener
|
||||||
|
..on<RoomDisconnectedEvent>((_) {
|
||||||
|
// handle disconnect
|
||||||
|
})
|
||||||
|
..on<ParticipantConnectedEvent>((e) {
|
||||||
|
print("participant joined: ${e.participant.identity}");
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
widget.room.delegate = null;
|
// be sure to dispose listener to stop listening to further updates
|
||||||
|
_listener.dispose();
|
||||||
|
widget.room.removeListener(_onChange);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,11 +174,6 @@ class _RoomState extends State<RoomWidget> with RoomDelegate {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onDisconnected() {
|
|
||||||
// onDisconnected is a RoomDelegate method, handle when disconnected from room
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// your build function
|
// your build function
|
||||||
@@ -187,7 +195,7 @@ class VideoView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VideoViewState extends State<VideoView> with ParticipantDelegate {
|
class _VideoViewState extends State<VideoView> {
|
||||||
TrackPublication? videoPub;
|
TrackPublication? videoPub;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user