From 097ce3be7afda3466c63013b805489fd6beafa57 Mon Sep 17 00:00:00 2001 From: Deveshi Dwivedi Date: Fri, 21 Jun 2024 00:48:19 +0530 Subject: [PATCH] add undo functionality --- common/types/global.d.ts | 1 + server/index.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/types/global.d.ts b/common/types/global.d.ts index 55e047c..9ea07bf 100644 --- a/common/types/global.d.ts +++ b/common/types/global.d.ts @@ -9,6 +9,7 @@ export declare global { options: CtxOptions, userId: string ) => void; + user_undo(userId: string): void; mouse_moved: (x:number, y:number, socketId: string) => void; users_in_room: (socketIds: string[]) => void; user_disconnected: (socketId: string) => void; diff --git a/server/index.ts b/server/index.ts index 288ebf6..b7c2e2c 100644 --- a/server/index.ts +++ b/server/index.ts @@ -27,7 +27,7 @@ io.on("connection", (socket)=>{ socket.on("draw", (moves, options)=>{ console.log("drawing"); - socket.broadcast.emit("socket_draw", moves, options); + socket.broadcast.emit("user_draw", moves, options, socket.id); }); socket.on("mouse_move", (x,y) => { @@ -36,6 +36,11 @@ io.on("connection", (socket)=>{ }); + socket.on("undo", ()=>{ + console.log("undo"); + socket.broadcast.emit("user_undo", socket.id); + }); + socket.on("disconnect", ()=>{ console.log("disconnected"); });