Skip to content

Commit

Permalink
add undo functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshidwivedi committed Jun 20, 2024
1 parent 6c94569 commit 097ce3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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");
});
Expand Down

0 comments on commit 097ce3b

Please sign in to comment.