diff --git a/src/lib/sync.ts b/src/lib/sync.ts index 0ce7fd9..31fe108 100644 --- a/src/lib/sync.ts +++ b/src/lib/sync.ts @@ -89,6 +89,7 @@ export class RoomSync { private onStateChange: SyncCallback; private onConnectionChange: ConnectionCallback; private participantId: string; + private currentParticipant: ParticipantState | null = null; constructor( slug: string, @@ -187,8 +188,12 @@ export class RoomSync { this.ws.onopen = () => { console.log('Connected to sync server'); this.onConnectionChange(true); - // Request current state from server - this.send({ type: 'request_state' }); + + // Send join message if we have participant info + if (this.currentParticipant) { + console.log('Sending join message for:', this.currentParticipant.name); + this.send({ type: 'join', participant: this.currentParticipant }); + } }; this.ws.onmessage = (event) => { @@ -280,7 +285,11 @@ export class RoomSync { // Public methods for updating state join(participant: ParticipantState): void { + // Store participant for sending after WebSocket connects + this.currentParticipant = participant; this.state.participants[participant.id] = participant; + + // Try to send join (will succeed if already connected) this.send({ type: 'join', participant }); this.notifyStateChange(); }