Skip to content

Commit 690f276

Browse files
authored
Ensure mute state stays in sync after reconnect (#965)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed mute state synchronization to ensure the client's local mute status remains in sync with the server, preventing inconsistencies during track publishing and codec operations. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 306b65e commit 690f276

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Keep mute state in sync with server"

lib/src/participant/local.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
104104
return participant;
105105
}
106106

107+
@override
108+
@internal
109+
Future<bool> updateFromInfo(lk_models.ParticipantInfo info) async {
110+
final didUpdate = await super.updateFromInfo(info);
111+
if (!didUpdate) return false;
112+
113+
// Reconcile local mute state with the server's copy.
114+
for (final trackInfo in info.tracks) {
115+
final pub = trackPublications[trackInfo.sid];
116+
if (pub == null) continue;
117+
118+
final localMuted = pub.muted;
119+
if (localMuted != trackInfo.muted) {
120+
logger.fine(
121+
'updating server mute state after reconcile, track: ${trackInfo.sid}, muted: $localMuted',
122+
);
123+
try {
124+
room.engine.signalClient.sendMuteTrack(trackInfo.sid, localMuted);
125+
} catch (e) {
126+
logger.warning('Failed to update server mute state after reconcile: $e');
127+
}
128+
}
129+
}
130+
131+
return true;
132+
}
133+
107134
/// Handle broadcast state change (iOS only)
108135
void _broadcastStateChanged() {
109136
final isEnabled = BroadcastManager().isBroadcasting && BroadcastManager().shouldPublishTrack;
@@ -870,6 +897,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
870897
: VideoPublishOptions.defaultCameraName),
871898
type: track.kind.toPBType(),
872899
source: track.source.toPBType(),
900+
muted: track.muted,
873901
layers: layers,
874902
sid: publication.sid,
875903
simulcastCodecs: <lk_rtc.SimulcastCodec>[

0 commit comments

Comments
 (0)