diff --git a/backend/src/Lobby.js b/backend/src/Lobby.js index 592af45..536207b 100644 --- a/backend/src/Lobby.js +++ b/backend/src/Lobby.js @@ -23,7 +23,7 @@ module.exports = class Lobby { this.name = name; } - run(ioLobby) { + run(io) { this.running = true; this.startTime = Date.now(); @@ -33,13 +33,12 @@ module.exports = class Lobby { return; } - const timestamp = timeline.getIndex(this.timelineIndex); const nextShot = timeline.getNextShot(this.timelineIndex); if (!timestamp) { // We are done. - ioLobby.emit('tick_event', { + io.to(this.name + "").emit('tick_event', { current: this.currentSeconds }); console.log("Done"); @@ -49,7 +48,7 @@ module.exports = class Lobby { console.log("ticking", this.currentSeconds); - ioLobby.emit('tick_event', { + io.to(this.name + "").emit('tick_event', { current: this.currentSeconds, next: timestamp, nextShot: nextShot @@ -72,14 +71,14 @@ module.exports = class Lobby { /** * - * @param ioLobby + * @param io * @param {number} time */ - seek(ioLobby, time) { + seek(io, time) { this.currentSeconds = time; this.startTime = Date.now() - time * 1000; this.timelineIndex = timeline.indexForTime(this.currentSeconds); - ioLobby.emit('seek', time); + io.to(this.name + "").emit('seek', time); } /** diff --git a/backend/src/index.js b/backend/src/index.js index 6a7d2c7..2a9c19c 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -69,13 +69,12 @@ io.on('connection', socket => { return; } - const ioLobby = io.to(lobby.name + ""); - ioLobby.emit('started'); - lobby.run(ioLobby); + io.to(lobby.name + "").emit('started'); + lobby.run(io); if (typeof time === 'number' && time) { console.log("Starting at", time); - lobby.seek(ioLobby, time); + lobby.seek(io, time); } }); }); \ No newline at end of file diff --git a/frontend/src/Wrapper.tsx b/frontend/src/Wrapper.tsx index 1af1c94..ed52bb9 100644 --- a/frontend/src/Wrapper.tsx +++ b/frontend/src/Wrapper.tsx @@ -35,7 +35,7 @@ const Wrapper = () => { // Won't play sound so we don't get DOM Interaction errors. setWantsToStart(true); } - }, []); + }, [noSound]); useSocket("tick_event", async (tick: Tick) => { if (!started && wantsToStart) { diff --git a/frontend/src/components/NextShot.tsx b/frontend/src/components/NextShot.tsx index 6e69fa7..367950d 100644 --- a/frontend/src/components/NextShot.tsx +++ b/frontend/src/components/NextShot.tsx @@ -15,6 +15,8 @@ const NextShot = () => { return; } + console.log("Tick event from NextShot"); + if (fullTime.current === 0) { fullTime.current = tick.nextShot.timestamp - tick.current; }