Skip to content

Commit 344e6ad

Browse files
committed
updated README with new event system
1 parent 4f064e0 commit 344e6ad

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ Audio tracks are rendered automatically as long as you are subscribed to them.
122122

123123
LiveKit client makes it simple to build declarative UI that reacts to state changes. It notifies changes in two ways
124124

125-
* `ChangeNotifier` - generic notification of changes
126-
* `RoomDelegate` and `ParticipantDelegate` - notification of specific events.
125+
* `ChangeNotifier` - generic notification of changes. This is useful when you are building reactive UI and only care about changes that may impact rendering.
126+
* `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)).
127127

128128
This example will show you how to use both to react to room events.
129129

@@ -139,17 +139,30 @@ class RoomWidget extends StatefulWidget {
139139
}
140140
}
141141
142-
class _RoomState extends State<RoomWidget> with RoomDelegate {
142+
class _RoomState extends State<RoomWidget> {
143+
late final EventsListener<RoomEvent> _listener = widget.room.createListener();
144+
143145
@override
144146
void initState() {
145147
super.initState();
146-
widget.room.delegate = this;
148+
// used for generic change updates
147149
widget.room.addListener(_onChange);
150+
151+
// used for specific events
152+
_listener
153+
..on<RoomDisconnectedEvent>((_) {
154+
// handle disconnect
155+
})
156+
..on<ParticipantConnectedEvent>((e) {
157+
print("participant joined: ${e.participant.identity}");
158+
})
148159
}
149160
150161
@override
151162
void dispose() {
152-
widget.room.delegate = null;
163+
// be sure to dispose listener to stop listening to further updates
164+
_listener.dispose();
165+
widget.room.removeListener(_onChange);
153166
super.dispose();
154167
}
155168
@@ -161,11 +174,6 @@ class _RoomState extends State<RoomWidget> with RoomDelegate {
161174
});
162175
}
163176
164-
@override
165-
void onDisconnected() {
166-
// onDisconnected is a RoomDelegate method, handle when disconnected from room
167-
}
168-
169177
@override
170178
Widget build(BuildContext context) {
171179
// your build function
@@ -187,7 +195,7 @@ class VideoView extends StatefulWidget {
187195
}
188196
}
189197
190-
class _VideoViewState extends State<VideoView> with ParticipantDelegate {
198+
class _VideoViewState extends State<VideoView> {
191199
TrackPublication? videoPub;
192200
193201
@override

0 commit comments

Comments
 (0)