Skip to content

Commit

Permalink
fix: Dispose LocalParticipant when room.disconnect. (#609)
Browse files Browse the repository at this point in the history
* fix: Optimize stats display

* fix: Dispose LocalParticipant when room.disconnect.
  • Loading branch information
cloudwebrtc authored Oct 21, 2024
1 parent 42558f6 commit 4851525
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
})
..on<EngineDisconnectedEvent>((event) async {
if (!engine.fullReconnectOnNext) {
await _cleanUp();
await _cleanUp(disposeLocalParticipant: false);
events.emit(RoomDisconnectedEvent(reason: event.reason));
notifyListeners();
}
Expand Down Expand Up @@ -887,7 +887,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {

extension RoomPrivateMethods on Room {
// resets internal state to a re-usable state
Future<void> _cleanUp() async {
Future<void> _cleanUp({bool disposeLocalParticipant = true}) async {
logger.fine('[${objectId}] cleanUp()');

// clean up RemoteParticipants
Expand All @@ -903,6 +903,11 @@ extension RoomPrivateMethods on Room {
// clean up LocalParticipant
await localParticipant?.unpublishAllTracks();

if (disposeLocalParticipant) {
await localParticipant?.dispose();
_localParticipant = null;
}

_activeSpeakers.clear();

// clean up engine
Expand Down

0 comments on commit 4851525

Please sign in to comment.