Skip to content

Commit 575d8b9

Browse files
committed
Patch Collab Space Notifs
1 parent 898e328 commit 575d8b9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Backend/CollabService/websocket/roomManagerSocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ function setupWebSocket(server) {
1313
switch (data.type) {
1414
case 'joinRoom':
1515
// add user into room with roomId
16-
manageRoom(ws, data.roomId, data.userId, "join");
16+
manageRoom(ws, data.roomId, data.username, "join");
1717
break;
1818
case 'leaveRoom':
1919
// remove user from room with roomId
20-
manageRoom(ws, data.roomId, data.userId, "leave");
20+
manageRoom(ws, data.roomId, data.username, "leave");
2121
break;
2222
case 'requestUserList':
2323
const users = getUsersInRoom(data.roomId);

Frontend/src/components/collab/CollaborationSpace.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,25 @@ const CollaborationSpace = () => {
9696
}
9797
}, [users])
9898

99-
const initiateWebSocket = (userId) => {
99+
const initiateWebSocket = (username) => {
100100
if (websocketRef.current) return; // Prevent duplicate connections
101101

102102
const websocket = new WebSocket("ws://localhost:3004");
103103
websocketRef.current = websocket;
104104

105+
console.log("In initiate websocket, the username is", username);
106+
105107
websocket.onopen = () => {
106108

107-
websocket.send(JSON.stringify({ type: 'joinRoom', roomId, userId }));
109+
websocket.send(JSON.stringify({ type: 'joinRoom', roomId, username }));
108110
websocket.send(JSON.stringify({ type: 'requestUserList', roomId }));
109111
};
110112

111113

112114
// on getting a reply from server
113115
websocket.onmessage = (event) => {
114116
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)}`);
116118
switch (data.type) {
117119
case 'usersListUpdate':
118120
setUsers(data.users); // Update the user list
@@ -200,7 +202,7 @@ const CollaborationSpace = () => {
200202
console.error("Failed to save session history:", error)
201203
}
202204

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 }));
204206

205207
// Clean up Yjs document and provider before going back to home
206208
if (provider) {
@@ -249,7 +251,7 @@ const CollaborationSpace = () => {
249251

250252
const handleLanguageChange = (value) => {
251253
websocketRef.current.send(JSON.stringify({ type: 'languageChange', roomId: roomId,
252-
user: userId, language: value }));
254+
user: username, language: value }));
253255
}
254256

255257
if (loading) {

0 commit comments

Comments
 (0)