@@ -96,23 +96,25 @@ const CollaborationSpace = () => {
96
96
}
97
97
} , [ users ] )
98
98
99
- const initiateWebSocket = ( userId ) => {
99
+ const initiateWebSocket = ( username ) => {
100
100
if ( websocketRef . current ) return ; // Prevent duplicate connections
101
101
102
102
const websocket = new WebSocket ( "ws://localhost:3004" ) ;
103
103
websocketRef . current = websocket ;
104
104
105
+ console . log ( "In initiate websocket, the username is" , username ) ;
106
+
105
107
websocket . onopen = ( ) => {
106
108
107
- websocket . send ( JSON . stringify ( { type : 'joinRoom' , roomId, userId } ) ) ;
109
+ websocket . send ( JSON . stringify ( { type : 'joinRoom' , roomId, username } ) ) ;
108
110
websocket . send ( JSON . stringify ( { type : 'requestUserList' , roomId } ) ) ;
109
111
} ;
110
112
111
113
112
114
// on getting a reply from server
113
115
websocket . onmessage = ( event ) => {
114
116
const data = JSON . parse ( event . data ) ;
115
- // console.log(`[FRONTEND] data message is ${JSON.stringify(data)}`);
117
+ console . log ( `[FRONTEND] data message is ${ JSON . stringify ( data ) } ` ) ;
116
118
switch ( data . type ) {
117
119
case 'usersListUpdate' :
118
120
setUsers ( data . users ) ; // Update the user list
@@ -200,7 +202,7 @@ const CollaborationSpace = () => {
200
202
console . error ( "Failed to save session history:" , error )
201
203
}
202
204
203
- if ( websocketRef . current ) websocketRef . current . send ( JSON . stringify ( { type : 'leaveRoom' , roomId, userId } ) ) ;
205
+ if ( websocketRef . current ) websocketRef . current . send ( JSON . stringify ( { type : 'leaveRoom' , roomId, username } ) ) ;
204
206
205
207
// Clean up Yjs document and provider before going back to home
206
208
if ( provider ) {
@@ -249,7 +251,7 @@ const CollaborationSpace = () => {
249
251
250
252
const handleLanguageChange = ( value ) => {
251
253
websocketRef . current . send ( JSON . stringify ( { type : 'languageChange' , roomId : roomId ,
252
- user : userId , language : value } ) ) ;
254
+ user : username , language : value } ) ) ;
253
255
}
254
256
255
257
if ( loading ) {
0 commit comments