Skip to content

Commit 9452f32

Browse files
authored
Fix/bug for sync state (#491)
1 parent 96a87cb commit 9452f32

File tree

11 files changed

+865
-45
lines changed

11 files changed

+865
-45
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
PROTO_DIR="../protocol"
1+
PROTO_DIR="../protocol/protobufs"
22

33
proto:
44
@{ \
55
if [ -d "$(PROTO_DIR)" ]; \
66
then \
77
protoc --dart_out=lib/src/proto -I$(PROTO_DIR) $(PROTO_DIR)/livekit_rtc.proto $(PROTO_DIR)/livekit_models.proto; \
88
else \
9-
echo "../protocol is not found. github.com/livekit/protocol must be checked out"; \
9+
echo "../protocol/protobufs is not found. github.com/livekit/protocol must be checked out"; \
1010
fi \
1111
}
1212

lib/src/core/engine.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// ignore_for_file: deprecated_member_use_from_same_package
16+
1517
import 'dart:async';
1618

1719
import 'package:flutter/foundation.dart';
@@ -829,6 +831,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
829831
void sendSyncState({
830832
required lk_rtc.UpdateSubscription subscription,
831833
required Iterable<lk_rtc.TrackPublishedResponse>? publishTracks,
834+
required List<String> trackSidsDisabled,
832835
}) async {
833836
final previousAnswer =
834837
(await subscriber?.pc.getLocalDescription())?.toPBType();
@@ -837,6 +840,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
837840
subscription: subscription,
838841
publishTracks: publishTracks,
839842
dataChannelInfo: dataChannelInfo(),
843+
trackSidsDisabled: trackSidsDisabled,
840844
);
841845
}
842846

lib/src/core/room.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// ignore_for_file: deprecated_member_use_from_same_package
16+
1517
import 'dart:async';
1618

1719
import 'package:flutter/foundation.dart';
@@ -707,15 +709,29 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
707709
}
708710

709711
Future<void> _sendSyncState() async {
710-
final sendUnSub = connectOptions.autoSubscribe;
711-
final participantTracks =
712-
remoteParticipants.values.map((e) => e.participantTracks());
712+
final autoSubscribe = connectOptions.autoSubscribe;
713+
714+
final trackSids = <String>[];
715+
final trackSidsDisabled = <String>[];
716+
717+
for (var participant in remoteParticipants.values) {
718+
for (var track in participant.trackPublications.values) {
719+
if (track.subscribed != autoSubscribe) {
720+
trackSids.add(track.sid);
721+
}
722+
if (!track.enabled) {
723+
trackSidsDisabled.add(track.sid);
724+
}
725+
}
726+
}
727+
713728
engine.sendSyncState(
714729
subscription: lk_rtc.UpdateSubscription(
715-
participantTracks: participantTracks,
716-
trackSids: participantTracks.map((e) => e.trackSids).flattened,
717-
subscribe: !sendUnSub,
730+
participantTracks: [],
731+
trackSids: trackSids,
732+
subscribe: !autoSubscribe,
718733
),
734+
trackSidsDisabled: trackSidsDisabled,
719735
publishTracks: localParticipant?.publishedTracksInfo(),
720736
);
721737
}

lib/src/core/signal_client.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,15 @@ extension SignalClientRequests on SignalClient {
530530
required lk_rtc.UpdateSubscription subscription,
531531
required Iterable<lk_rtc.TrackPublishedResponse>? publishTracks,
532532
required Iterable<lk_rtc.DataChannelInfo>? dataChannelInfo,
533+
required List<String> trackSidsDisabled,
533534
}) =>
534535
_sendRequest(lk_rtc.SignalRequest(
535536
syncState: lk_rtc.SyncState(
536537
answer: answer,
537538
subscription: subscription,
538539
publishTracks: publishTracks,
539540
dataChannels: dataChannelInfo,
541+
trackSidsDisabled: trackSidsDisabled,
540542
),
541543
));
542544

lib/src/participant/local.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// ignore_for_file: deprecated_member_use_from_same_package
16+
1517
import 'package:flutter/foundation.dart';
1618

1719
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;

0 commit comments

Comments
 (0)