feat: restructure client-side code
This commit is contained in:
13
src/server/game/sync.js
Normal file
13
src/server/game/sync.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { broadcast } from './state.js';
|
||||
|
||||
export function startSyncTimer(room) {
|
||||
if (room.syncTimer) clearInterval(room.syncTimer);
|
||||
room.syncTimer = setInterval(() => {
|
||||
if (room.state.status !== 'playing' || !room.state.currentTrack || !room.state.trackStartAt || room.state.paused) return;
|
||||
broadcast(room, 'sync', { startAt: room.state.trackStartAt, serverNow: Date.now() });
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
export function stopSyncTimer(room) {
|
||||
if (room.syncTimer) { clearInterval(room.syncTimer); room.syncTimer = null; }
|
||||
}
|
||||
Reference in New Issue
Block a user