refactor(watch-together): share host peer IDs

This commit is contained in:
edde746
2026-07-12 08:42:22 +02:00
parent 65d3d8e471
commit 79dabaf125
4 changed files with 19 additions and 2 deletions
+2
View File
@@ -1,5 +1,7 @@
int watchTogetherSystemNowMs() => DateTime.now().millisecondsSinceEpoch;
String watchTogetherHostPeerId(String sessionId) => 'wt-${sessionId.toUpperCase()}';
bool orderedStringListsEqual(List<String> first, List<String> second) {
if (first.length != second.length) return false;
for (var i = 0; i < first.length; i++) {
@@ -10,6 +10,7 @@ import '../../utils/app_logger.dart';
import '../models/playback_state.dart';
import '../models/sync_message.dart';
import '../models/watch_session.dart';
import '../primitives.dart';
import '../services/current_playback_dispatcher.dart';
import '../services/watch_together_controller.dart';
import '../services/watch_together_peer_service.dart';
@@ -368,7 +369,7 @@ class WatchTogetherProvider with ChangeNotifier {
await _peerService!.joinSession(sessionId);
// Session will be fully configured when we receive sessionConfig from host
_session = _session!.copyWith(state: SessionState.connected, hostPeerId: 'wt-${sessionId.toUpperCase()}');
_session = _session!.copyWith(state: SessionState.connected, hostPeerId: watchTogetherHostPeerId(sessionId));
_displayName = displayName ?? _generateDisplayName();
@@ -10,6 +10,7 @@ import '../../i18n/strings.g.dart';
import '../../services/base_peer_service.dart';
import '../../utils/app_logger.dart';
import '../models/sync_message.dart';
import '../primitives.dart';
// Re-export so existing callers that import from here keep working.
export '../../services/base_peer_service.dart' show PeerError, PeerErrorType;
@@ -352,7 +353,7 @@ class WatchTogetherPeerService with KeepaliveMixin {
_isHost = true;
_sessionId = sessionId?.toUpperCase() ?? _generateSessionId();
_myPeerId = 'wt-$_sessionId';
_myPeerId = watchTogetherHostPeerId(_sessionId!);
_reconnectAttempts = 0;
try {