add view socket
This commit is contained in:
@@ -60,6 +60,7 @@ app.use(morgan("tiny"));
|
||||
// Global
|
||||
let data = null;
|
||||
let selectedOptionId = null;
|
||||
let lookingAtIdx = 0;
|
||||
|
||||
// Socket connection handling
|
||||
io.on("connection", (socket) => {
|
||||
@@ -67,6 +68,7 @@ io.on("connection", (socket) => {
|
||||
|
||||
socket.emit("dataChanged", data);
|
||||
socket.emit("selectedOptionChanged", selectedOptionId);
|
||||
socket.emit("lookingAtIdxChanged", lookingAtIdx);
|
||||
|
||||
// Handle array updates from client
|
||||
socket.on("setData", (newData) => {
|
||||
@@ -81,6 +83,12 @@ io.on("connection", (socket) => {
|
||||
io.emit("selectedOptionChanged", newId);
|
||||
});
|
||||
|
||||
socket.on("setLookingAtIdx", (newIdx) => {
|
||||
lookingAtIdx = 0;
|
||||
console.log("Looking at id changed to ", newIdx);
|
||||
io.emit("lookingAtIdxChanged", newIdx);
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("Client disconnected:", socket.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user