fix: watch together room re-join and participant discovery

close #875
This commit is contained in:
edde746
2026-04-16 13:17:24 +02:00
parent 360741674d
commit 3cf1ebc09b
4 changed files with 49 additions and 25 deletions
@@ -304,15 +304,16 @@ class WatchTogetherProvider with ChangeNotifier {
final probe = WatchTogetherPeerService(customBaseUrl: customRelayUrl);
try {
final becameHost = await probe.joinOrCreateSession(sessionId);
final shouldBeHost = becameHost || probe.connectedPeers.isEmpty;
await probe.disconnect();
probe.dispose();
if (becameHost) {
if (shouldBeHost) {
await createSession(controlMode: controlMode, displayName: displayName, sessionId: sessionId);
} else {
await joinSession(sessionId, displayName: displayName);
}
return becameHost;
return shouldBeHost;
} catch (e) {
await probe.disconnect();
probe.dispose();
@@ -460,14 +461,13 @@ class WatchTogetherProvider with ChangeNotifier {
);
}
// If we're the host, send our join info back so the new peer
// adds us to their participant list. This is done at provider
// level (in addition to sync manager) so it works even when
// no player is attached yet.
if (isHost && _peerService != null) {
// Send our join info back so the new peer adds us to their
// participant list. Every peer does this (not just the host)
// so that late joiners learn about all existing participants.
if (_peerService != null) {
_peerService!.sendTo(
message.peerId!,
SyncMessage.join(peerId: _peerService!.myPeerId!, displayName: _displayName, isHost: true),
SyncMessage.join(peerId: _peerService!.myPeerId!, displayName: _displayName, isHost: isHost),
);
}