Skip to content

Commit e2bb840

Browse files
sonyahu15namos2502HadriChanr-mcgrath
committed
debugging rooms
Co-authored-by: Nam <[email protected]> Co-authored-by: HadriChan <[email protected]> Co-authored-by: r-mcgrath <[email protected]>
1 parent f21d7d0 commit e2bb840

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

app/src/components/left/RoomsContainer.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const RoomsContainer = () => {
3838
userJoined: store.roomSlice.userJoined
3939
})
4040
);
41+
4142
React.useEffect(() => {
4243
console.log('You Joined Room---:', roomCode);
4344
}, [roomCode]);
@@ -72,15 +73,22 @@ const RoomsContainer = () => {
7273
if (currentStore !== event) {
7374
currentStore = JSON.parse(currentStore);
7475
event = JSON.parse(event);
75-
if (currentStore.appState !== event.appState) {
76+
if (
77+
JSON.stringify(currentStore.appState) !==
78+
JSON.stringify(event.appState)
79+
) {
7680
console.log('updating app state');
7781
store.dispatch(allCooperativeState(event.appState));
7882
} else if (
79-
currentStore.codePreviewSlice !== event.codePreviewCooperative
83+
JSON.stringify(currentStore.codePreviewSlice) !==
84+
JSON.stringify(event.codePreviewCooperative)
8085
) {
8186
console.log('updating code preview');
8287
store.dispatch(codePreviewCooperative(event.codePreviewCooperative));
83-
} else if (currentStore.styleSlice !== event.styleSlice) {
88+
} else if (
89+
JSON.stringify(currentStore.styleSlice) !==
90+
JSON.stringify(event.styleSlice)
91+
) {
8492
console.log('updating style');
8593
store.dispatch(cooperativeStyle(event.styleSlice));
8694
}
@@ -98,23 +106,23 @@ const RoomsContainer = () => {
98106
const newState = store.getState();
99107
const roomCode = newState.roomSlice.roomCode;
100108

101-
if (newState !== previousState) {
109+
if (JSON.stringify(newState) !== JSON.stringify(previousState)) {
102110
// Send the current state to the server
103111
console.log('front emitting new state');
104112
socket.emit('new state from front', JSON.stringify(newState), roomCode);
105113
previousState = newState;
106114
}
107-
}, 10000);
115+
}, 100);
108116

109117
store.subscribe(() => {
110118
if (socket) {
111-
console.log('handling store change');
119+
//console.log('handling store change');
112120
handleStoreChange();
113121
}
114122
});
115123

116124
function joinRoom() {
117-
if (userList.length !== 0) setUserList([]); //edge case check if userList not empty.
125+
if (userList.length !== 0) dispatch(setUserList([])); //edge case check if userList not empty.
118126
handleUserEnteredRoom(roomCode); // Call handleUserEnteredRoom when joining a room
119127
dispatch(setRoomCode(roomCode));
120128
dispatch(setUserJoined(true)); //setting joined room to true for rendering leave room button
@@ -131,12 +139,11 @@ const RoomsContainer = () => {
131139
}
132140

133141
//checking if both text field have any input (not including spaces)
134-
function checkInputField(...inputs: any) {
142+
function checkInputField(...inputs) {
135143
let userName: string = inputs[0].trim();
136144
let roomCode: string = inputs[1].trim();
137145
return userName.length === 0 || roomCode.length === 0;
138146
}
139-
140147
return (
141148
<div>
142149
<Stack //stack styling for container

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const initialState: State = {
1717
forked: false,
1818
published: false,
1919
isLoggedIn: false,
20-
config: { saveFlag: true, saveTimer: false },
20+
//config: { saveFlag: true, saveTimer: false },
2121
components: [
2222
{
2323
id: 1,

server/server.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ const io = new Server(httpServer, {
9898
const roomLists = {}; //key: roomCode, value: Obj{ socketid: username }
9999
io.on('connection', (client) => {
100100
client.on('new state from front', (redux_store, room) => {
101-
console.log('back receiving new state');
101+
//console.log('back receiving new state');
102102
if (room) {
103103
//sending to sender client, only if they are in room
104104
console.log('back emitting new state to room');
105105
client.to(room).emit('new state from back', redux_store);
106-
} else {
107-
//send to all connected clients except the one that sent the message
108-
console.log('back emitting new state broadcast');
109-
client.broadcast.emit('new state from back', redux_store);
110106
}
107+
// } else {
108+
// //send to all connected clients except the one that sent the message
109+
// console.log('back emitting new state broadcast');
110+
// client.broadcast.emit('new state from back', redux_store);
111+
// }
111112
});
112113

113114
// client.on('join-room', (roomCode) => {

webpack.development.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = merge(base, {
1818
port: '8080',
1919
hot: true, // Hot-reload this server if changes are detected
2020
compress: true, // Compress (gzip) files that are served
21-
// contentBase: path.resolve(__dirname, 'app/dist'), // Where we serve the local dev server's files from, not valid devserver
21+
// contentBase: path.resolve(__dirname, 'app/dist')
22+
// Where we serve the local dev server's files from, not valid devserver
2223
// watchContentBase: true, // Watch the content base for changes , also not valid for dev server
2324
// watchOptions: {
2425
// ignored: /node_modules/,

0 commit comments

Comments
 (0)