refactor(watch-together): share host peer IDs
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -2,6 +2,19 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/watch_together/primitives.dart';
|
||||
|
||||
void main() {
|
||||
test('host and guest derive the same host peer ID', () {
|
||||
final hostPeerId = watchTogetherHostPeerId('ROOM1');
|
||||
final guestExpectedHostPeerId = watchTogetherHostPeerId('room1');
|
||||
|
||||
expect(guestExpectedHostPeerId, hostPeerId);
|
||||
});
|
||||
|
||||
test('stored room codes preserve the established host peer wire format', () {
|
||||
const persistedSessionId = 'Ab12z';
|
||||
|
||||
expect(watchTogetherHostPeerId(persistedSessionId), 'wt-AB12Z');
|
||||
});
|
||||
|
||||
test('orderedStringListsEqual preserves order and multiplicity', () {
|
||||
expect(orderedStringListsEqual(const ['a', 'b'], const ['a', 'b']), isTrue);
|
||||
expect(orderedStringListsEqual(const ['a'], const ['a', 'b']), isFalse);
|
||||
|
||||
Reference in New Issue
Block a user