diff --git a/server/src/index.js b/server/src/index.js index 2f575d5a..df375f68 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -35,7 +35,6 @@ app.get("/things/:ids", cors({ origin: corsOrigins}), async (req, res) => { }); function cleanID(id) { - console.log(id); if (!id) return null; if (typeof id !== "string") return id.id || null; // no real id oops if (id.startsWith("rec") && id.length === 17) id = id.slice(3); @@ -55,6 +54,12 @@ io.on("connection", (socket) => { id = cleanID(id); socket.leave(id); }); + socket.on("subscribe-multiple", (ids) => { + console.log(`[multiple] client rejoining ${ids.length} rooms`); + ids.map(id => cleanID(id)).forEach(id => { + socket.join(id); + }); + }); }); http.listen(port, () => { diff --git a/website/src/main.js b/website/src/main.js index 50d3eb35..981f0b18 100644 --- a/website/src/main.js +++ b/website/src/main.js @@ -38,7 +38,8 @@ const app = new Vue({ store, sockets: { connect() { - console.log("[socket]", "connected"); + console.log("[socket]", "connected", this.$store.state.subscribed_ids.length); + this.$socket.client.emit("subscribe-multiple", this.$store.state.subscribed_ids); }, data_update(d) { // handled by vuex diff --git a/website/src/thing-store.js b/website/src/thing-store.js index bd48da34..5b9688ef 100644 --- a/website/src/thing-store.js +++ b/website/src/thing-store.js @@ -51,12 +51,14 @@ export default new Vuex.Store({ this.commit("push", { id, data }); }, subscribe(state, id) { + if (!id) return; if (state.subscribed_ids.includes(id)) return; this._vm.$socket.client.emit("subscribe", id); // console.log("[socket]", "subscribed to", id); state.subscribed_ids.push(id); }, unsubscribe(state, id) { + if (!id) return; if (!state.subscribed_ids.includes(id)) return; this._vm.$socket.client.emit("unsubscribe", id); // console.log("[socket]", "unsubscribed from", id);