@@ -85,21 +85,18 @@ wss.on("connection", function connection(ws, req) {
85
85
} ;
86
86
connections . push ( newConnection ) ;
87
87
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 ) ;
89
95
90
96
ws . on ( "error" , ( err ) =>
91
97
console . error ( `WebSocket error for user ${ userId } :` , err )
92
98
) ;
93
99
94
- ws . on ( "open" , ( ) => {
95
- ws . send (
96
- JSON . stringify ( {
97
- type : WsDataType . CONNECTION_READY ,
98
- connectionId,
99
- } )
100
- ) ;
101
- } ) ;
102
-
103
100
ws . on ( "message" , async function message ( data ) {
104
101
try {
105
102
const parsedData : WebSocketMessage = JSON . parse ( data . toString ( ) ) ;
@@ -299,6 +296,51 @@ wss.on("connection", function connection(ws, req) {
299
296
}
300
297
}
301
298
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
+
302
344
case WsDataType . DRAW : {
303
345
if ( ! parsedData . message || ! parsedData . id || ! parsedData . roomId ) {
304
346
console . error (
0 commit comments