Skip to content

Commit eeb6b1d

Browse files
committed
Merge branch 'dev' into sonya-exploring
2 parents 322c6f2 + bbb036b commit eeb6b1d

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

app/src/components/left/RoomsContainer.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,19 @@ const RoomsContainer = () => {
4949
socket.emit('join-room', roomCode); // Join the room when connected
5050
//passing current client nickname to server
5151
console.log(`Your Nickname Is: ${userName}`);
52-
socket.emit('user', userName);
52+
socket.emit('userJoined', userName);
5353
});
54-
55-
// // Receiving the room state from the backend
56-
// socket.on('room-state-update', (stateFromServer) => {
57-
// const newState = JSON.parse(stateFromServer);
58-
// // Dispatch actions to update your Redux store with the received state
59-
// store.dispatch(allCooperativeState(newState.appState));
60-
// store.dispatch(codePreviewCooperative(newState.codePreviewCooperative));
61-
// store.dispatch(cooperativeStyle(newState.styleSlice));
62-
// });
54+
6355

6456
// receiving the message from the back end
6557
socket.on('receive message', (event) => {
6658
let currentStore: any = JSON.stringify(store.getState());
59+
console.log('event ', event);
6760
if (currentStore !== event) {
6861
currentStore = JSON.parse(currentStore);
6962
event = JSON.parse(event);
63+
console.log('current store', currentStore);
64+
console.log('event ', event);
7065
if (currentStore.appState !== event.appState) {
7166
store.dispatch(allCooperativeState(event.appState));
7267
} else if (
@@ -104,6 +99,7 @@ const RoomsContainer = () => {
10499
);
105100
previousState = newState;
106101
}
102+
107103
}, 100);
108104

109105
store.subscribe(() => {

app/src/redux/reducers/slice/roomSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createSlice } from '@reduxjs/toolkit';
44
const initialState = {
55
roomCode: '',
66
userName: '',
7-
userList: new Map(),
7+
userList: [],
88
userJoined: false
99
};
1010

server/server.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,35 @@ const io = new Server(httpServer, {
9595
}
9696
});
9797
//creating map for user list
98-
const userList = new Map();
98+
const userList = {};
9999
io.on('connection', (socket) => {
100-
101100
console.log('Socket ID: -----', socket.id);
102101
socket.on('custom-event', (redux_store, room) => {
103102
if (room) {
104103
//sending to sender client, only if they are in room
104+
console.log('emiting to room receive message event to front end');
105105
socket.to(room).emit('receive message', redux_store);
106106
} else {
107107
//send to all connected clients except the one that sent the message
108+
console.log('emiting broadcast receive message event to front end');
108109
socket.broadcast.emit('receive message', redux_store);
109110
}
110111
});
111112
socket.on('room-code', (roomCode) => {
112113
//working
113114
socket.join(roomCode);
114115
});
115-
socket.on('user', (userName) => {
116+
socket.on('userJoined', (userName) => {
116117
//working
117-
userList.set(socket.id, userName);
118-
io.emit('updateUserList', userList);
118+
userList[socket.id] = userName;
119+
io.emit('updateUserList', userList); //work on this
119120
});
120121
socket.on('disconnect', () => {
121-
const userName = userList.get(socket.id);
122+
const userName = userList[socket.id];
122123
console.log('User list before remove user', userList);
123-
userList.delete(socket.id); //remove the user from the obj
124+
delete userList[socket.id]; //remove the user from the obj
124125
console.log('User list after remove user', userList);
125-
io.emit('disconnected', userName);
126+
io.emit('updateUserList', userList); //check this
126127
});
127128
});
128129

0 commit comments

Comments
 (0)