From f93f3c063cb55f72b55efd08e3fde9e5e8364caf Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 14 Jun 2022 17:12:37 +0800 Subject: [PATCH] re-send tracks permissions after reconnected. (#128) --- lib/src/core/room.dart | 2 ++ lib/src/participant/local.dart | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index c41a7593..9ca41e21 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -218,6 +218,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable { void _setUpEngineListeners() => _engineListener ..on((event) async { if (event.didReconnect) { + // re-send tracks permissions + localParticipant?.sendTrackSubscriptionPermissions(); events.emit(const RoomReconnectedEvent()); await _handlePostReconnect(false); } else if (event.newState == ConnectionState.reconnecting) { diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index 2fe68750..c662ec5d 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -322,6 +322,9 @@ class LocalParticipant extends Participant { return null; } + bool _allParticipantsAllowed = true; + List _participantTrackPermissions = []; + /// Control who can subscribe to LocalParticipant's published tracks. /// /// By default, all participants can subscribe. This allows fine-grained control over @@ -342,11 +345,22 @@ class LocalParticipant extends Participant { void setTrackSubscriptionPermissions({ required bool allParticipantsAllowed, List trackPermissions = const [], - }) => - room.engine.signalClient.sendUpdateSubscriptionPermissions( - allParticipants: allParticipantsAllowed, - trackPermissions: trackPermissions.map((e) => e.toPBType()).toList(), - ); + }) { + _allParticipantsAllowed = allParticipantsAllowed; + _participantTrackPermissions = trackPermissions; + sendTrackSubscriptionPermissions(); + } + + void sendTrackSubscriptionPermissions() { + if (room.engine.connectionState != ConnectionState.connected) { + return; + } + room.engine.signalClient.sendUpdateSubscriptionPermissions( + allParticipants: _allParticipantsAllowed, + trackPermissions: + _participantTrackPermissions.map((e) => e.toPBType()).toList(), + ); + } @internal Iterable publishedTracksInfo() =>