Skip to content

Commit

Permalink
Fix/bug for sync state (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Apr 5, 2024
1 parent 96a87cb commit 9452f32
Show file tree
Hide file tree
Showing 11 changed files with 865 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PROTO_DIR="../protocol"
PROTO_DIR="../protocol/protobufs"

proto:
@{ \
if [ -d "$(PROTO_DIR)" ]; \
then \
protoc --dart_out=lib/src/proto -I$(PROTO_DIR) $(PROTO_DIR)/livekit_rtc.proto $(PROTO_DIR)/livekit_models.proto; \
else \
echo "../protocol is not found. github.com/livekit/protocol must be checked out"; \
echo "../protocol/protobufs is not found. github.com/livekit/protocol must be checked out"; \
fi \
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';

import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -829,6 +831,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
void sendSyncState({
required lk_rtc.UpdateSubscription subscription,
required Iterable<lk_rtc.TrackPublishedResponse>? publishTracks,
required List<String> trackSidsDisabled,
}) async {
final previousAnswer =
(await subscriber?.pc.getLocalDescription())?.toPBType();
Expand All @@ -837,6 +840,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
subscription: subscription,
publishTracks: publishTracks,
dataChannelInfo: dataChannelInfo(),
trackSidsDisabled: trackSidsDisabled,
);
}

Expand Down
28 changes: 22 additions & 6 deletions lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';

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

Future<void> _sendSyncState() async {
final sendUnSub = connectOptions.autoSubscribe;
final participantTracks =
remoteParticipants.values.map((e) => e.participantTracks());
final autoSubscribe = connectOptions.autoSubscribe;

final trackSids = <String>[];
final trackSidsDisabled = <String>[];

for (var participant in remoteParticipants.values) {
for (var track in participant.trackPublications.values) {
if (track.subscribed != autoSubscribe) {
trackSids.add(track.sid);
}
if (!track.enabled) {
trackSidsDisabled.add(track.sid);
}
}
}

engine.sendSyncState(
subscription: lk_rtc.UpdateSubscription(
participantTracks: participantTracks,
trackSids: participantTracks.map((e) => e.trackSids).flattened,
subscribe: !sendUnSub,
participantTracks: [],
trackSids: trackSids,
subscribe: !autoSubscribe,
),
trackSidsDisabled: trackSidsDisabled,
publishTracks: localParticipant?.publishedTracksInfo(),
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,15 @@ extension SignalClientRequests on SignalClient {
required lk_rtc.UpdateSubscription subscription,
required Iterable<lk_rtc.TrackPublishedResponse>? publishTracks,
required Iterable<lk_rtc.DataChannelInfo>? dataChannelInfo,
required List<String> trackSidsDisabled,
}) =>
_sendRequest(lk_rtc.SignalRequest(
syncState: lk_rtc.SyncState(
answer: answer,
subscription: subscription,
publishTracks: publishTracks,
dataChannels: dataChannelInfo,
trackSidsDisabled: trackSidsDisabled,
),
));

Expand Down
2 changes: 2 additions & 0 deletions lib/src/participant/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: deprecated_member_use_from_same_package

import 'package:flutter/foundation.dart';

import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
Expand Down
Loading

0 comments on commit 9452f32

Please sign in to comment.