Fix multiple lobbies interleaving

master
Wilco Kruijer 4 years ago
parent 8482deb7e5
commit 3e514d3857
  1. 13
      backend/src/Lobby.js
  2. 7
      backend/src/index.js
  3. 2
      frontend/src/Wrapper.tsx
  4. 2
      frontend/src/components/NextShot.tsx

@ -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);
}
/**

@ -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);
}
});
});

@ -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) {

@ -15,6 +15,8 @@ const NextShot = () => {
return;
}
console.log("Tick event from NextShot");
if (fullTime.current === 0) {
fullTime.current = tick.nextShot.timestamp - tick.current;
}

Loading…
Cancel
Save