@@ -85,21 +85,18 @@ wss.on("connection", function connection(ws, req) {
8585 } ;
8686 connections . push ( newConnection ) ;
8787
88- console . log ( `New connection established: ${ connectionId } for user ${ userId } ` ) ;
88+ ws . send (
89+ JSON . stringify ( {
90+ type : WsDataType . CONNECTION_READY ,
91+ connectionId,
92+ } )
93+ ) ;
94+ console . log ( "✅ Sent CONNECTION_READY to:" , connectionId ) ;
8995
9096 ws . on ( "error" , ( err ) =>
9197 console . error ( `WebSocket error for user ${ userId } :` , err )
9298 ) ;
9399
94- ws . on ( "open" , ( ) => {
95- ws . send (
96- JSON . stringify ( {
97- type : WsDataType . CONNECTION_READY ,
98- connectionId,
99- } )
100- ) ;
101- } ) ;
102-
103100 ws . on ( "message" , async function message ( data ) {
104101 try {
105102 const parsedData : WebSocketMessage = JSON . parse ( data . toString ( ) ) ;
@@ -299,6 +296,51 @@ wss.on("connection", function connection(ws, req) {
299296 }
300297 }
301298
299+ case WsDataType . CURSOR_MOVE :
300+ if (
301+ parsedData . roomId &&
302+ parsedData . userId &&
303+ parsedData . connectionId &&
304+ parsedData . message
305+ ) {
306+ broadcastToRoom (
307+ parsedData . roomId ,
308+ {
309+ type : parsedData . type ,
310+ roomId : parsedData . roomId ,
311+ userId : connection . userId ,
312+ userName : connection . userName ,
313+ connectionId : connection . connectionId ,
314+ message : parsedData . message ,
315+ timestamp : new Date ( ) . toISOString ( ) ,
316+ id : null ,
317+ participants : null ,
318+ } ,
319+ [ parsedData . connectionId ] ,
320+ false
321+ ) ;
322+ }
323+ break ;
324+
325+ case WsDataType . STREAM_SHAPE :
326+ broadcastToRoom (
327+ parsedData . roomId ,
328+ {
329+ type : parsedData . type ,
330+ id : parsedData . id ,
331+ message : parsedData . message ,
332+ roomId : parsedData . roomId ,
333+ userId : connection . userId ,
334+ userName : connection . userName ,
335+ connectionId : connection . connectionId ,
336+ timestamp : new Date ( ) . toISOString ( ) ,
337+ participants : null ,
338+ } ,
339+ [ connection . connectionId ] ,
340+ false
341+ ) ;
342+ break ;
343+
302344 case WsDataType . DRAW : {
303345 if ( ! parsedData . message || ! parsedData . id || ! parsedData . roomId ) {
304346 console . error (
0 commit comments