@@ -35,88 +35,88 @@ import withStyles from '@mui/styles/withStyles';
35
35
const { API_BASE_URL } = config ;
36
36
37
37
// Part - join room and room code functionality
38
- let socket ;
39
-
40
- function initSocketConnection ( roomCode ) {
41
- if ( socket ) {
42
- socket . disconnect ( ) ;
43
- }
44
-
45
- socket = io ( API_BASE_URL , {
46
- transports : [ 'websocket' ]
47
- } ) ;
48
-
49
- socket . on ( 'connect' , ( ) => {
50
- console . log ( `You connected with id: ${ socket . id } ` ) ;
51
- socket . emit ( 'join-room' , roomCode ) ; // Join the room when connected
52
- } ) ;
53
-
54
- // Receiving the room state from the backend
55
- socket . on ( 'room-state-update' , ( stateFromServer ) => {
56
- const newState = JSON . parse ( stateFromServer ) ;
57
- // Dispatch actions to update your Redux store with the received state
58
- store . dispatch ( allCooperativeState ( newState . appState ) ) ;
59
- store . dispatch ( codePreviewCooperative ( newState . codePreviewCooperative ) ) ;
60
- store . dispatch ( cooperativeStyle ( newState . styleSlice ) ) ;
61
- } ) ;
62
-
63
- // receiving the message from the back end
64
- socket . on ( 'receive message' , ( event ) => {
65
- // console.log('message from server: ', event);
66
- let currentStore : any = JSON . stringify ( store . getState ( ) ) ;
67
- if ( currentStore !== event ) {
68
- currentStore = JSON . parse ( currentStore ) ;
69
- event = JSON . parse ( event ) ;
70
- if ( currentStore . darkMode . isDarkMode !== event . darkMode . isDarkMode ) {
71
- store . dispatch ( toggleDarkMode ( ) ) ;
72
- } else if ( currentStore . appState !== event . appState ) {
73
- store . dispatch ( allCooperativeState ( event . appState ) ) ;
74
- } else if (
75
- currentStore . codePreviewSlice !== event . codePreviewCooperative
76
- ) {
77
- store . dispatch ( codePreviewCooperative ( event . codePreviewCooperative ) ) ;
78
- } else if ( currentStore . styleSlice !== event . styleSlice ) {
79
- store . dispatch ( cooperativeStyle ( event . styleSlice ) ) ;
80
- }
81
- }
82
- console . log ( 'updated user Store from another user: ' , store . getState ( ) ) ;
83
- } ) ;
84
- }
85
-
86
- function handleUserEnteredRoom ( roomCode ) {
87
- initSocketConnection ( roomCode ) ;
88
- }
89
-
90
- // console.log(store.getState());
91
- let previousState = store . getState ( ) ;
92
-
93
- // sending info to backend whenever the redux store changes
94
- const handleStoreChange = debounce ( ( ) => {
95
- const newState = store . getState ( ) ;
96
- const roomCode = newState . roomCodeSlice . roomCode ;
97
-
98
- if ( roomCode !== '' ) {
99
- // Emit the current room code
100
- socket . emit ( 'room-code' , roomCode ) ;
101
- }
102
-
103
- if ( newState !== previousState ) {
104
- // Send the current state to the server
105
- socket . emit (
106
- 'custom-event' ,
107
- 'sent from front-end' ,
108
- JSON . stringify ( newState ) ,
109
- roomCode
110
- ) ;
111
- previousState = newState ;
112
- }
113
- } , 100 ) ;
114
-
115
- store . subscribe ( ( ) => {
116
- if ( socket ) {
117
- handleStoreChange ( ) ;
118
- }
119
- } ) ;
38
+ // let socket;
39
+
40
+ // function initSocketConnection(roomCode) {
41
+ // if (socket) {
42
+ // socket.disconnect();
43
+ // }
44
+
45
+ // socket = io(API_BASE_URL, {
46
+ // transports: ['websocket']
47
+ // });
48
+
49
+ // socket.on('connect', () => {
50
+ // console.log(`You connected with id: ${socket.id}`);
51
+ // socket.emit('join-room', roomCode); // Join the room when connected
52
+ // });
53
+
54
+ // // Receiving the room state from the backend
55
+ // socket.on('room-state-update', (stateFromServer) => {
56
+ // const newState = JSON.parse(stateFromServer);
57
+ // // Dispatch actions to update your Redux store with the received state
58
+ // store.dispatch(allCooperativeState(newState.appState));
59
+ // store.dispatch(codePreviewCooperative(newState.codePreviewCooperative));
60
+ // store.dispatch(cooperativeStyle(newState.styleSlice));
61
+ // });
62
+
63
+ // // receiving the message from the back end
64
+ // socket.on('receive message', (event) => {
65
+ // // console.log('message from server: ', event);
66
+ // let currentStore: any = JSON.stringify(store.getState());
67
+ // if (currentStore !== event) {
68
+ // currentStore = JSON.parse(currentStore);
69
+ // event = JSON.parse(event);
70
+ // if (currentStore.darkMode.isDarkMode !== event.darkMode.isDarkMode) {
71
+ // store.dispatch(toggleDarkMode());
72
+ // } else if (currentStore.appState !== event.appState) {
73
+ // store.dispatch(allCooperativeState(event.appState));
74
+ // } else if (
75
+ // currentStore.codePreviewSlice !== event.codePreviewCooperative
76
+ // ) {
77
+ // store.dispatch(codePreviewCooperative(event.codePreviewCooperative));
78
+ // } else if (currentStore.styleSlice !== event.styleSlice) {
79
+ // store.dispatch(cooperativeStyle(event.styleSlice));
80
+ // }
81
+ // }
82
+ // console.log('updated user Store from another user: ', store.getState());
83
+ // });
84
+ // }
85
+
86
+ // function handleUserEnteredRoom(roomCode) {
87
+ // initSocketConnection(roomCode);
88
+ // }
89
+
90
+ // // console.log(store.getState());
91
+ // let previousState = store.getState();
92
+
93
+ // // sending info to backend whenever the redux store changes
94
+ // const handleStoreChange = debounce(() => {
95
+ // const newState = store.getState();
96
+ // const roomCode = newState.roomCodeSlice.roomCode;
97
+
98
+ // if (roomCode !== '') {
99
+ // // Emit the current room code
100
+ // socket.emit('room-code', roomCode);
101
+ // }
102
+
103
+ // if (newState !== previousState) {
104
+ // // Send the current state to the server
105
+ // socket.emit(
106
+ // 'custom-event',
107
+ // 'sent from front-end',
108
+ // JSON.stringify(newState),
109
+ // roomCode
110
+ // );
111
+ // previousState = newState;
112
+ // }
113
+ // }, 100);
114
+
115
+ // store.subscribe(() => {
116
+ // if (socket) {
117
+ // handleStoreChange();
118
+ // }
119
+ // });
120
120
121
121
const useStyles = makeStyles ( ( theme ) =>
122
122
createStyles ( {
@@ -254,9 +254,9 @@ function navbarDropDown(props) {
254
254
props . setDropMenu ( false ) ;
255
255
} ;
256
256
257
- React . useEffect ( ( ) => {
258
- console . log ( 'joinedRoom: ' , joinedRoom ) ;
259
- } , [ joinedRoom ] ) ;
257
+ // React.useEffect(() => {
258
+ // console.log('joinedRoom: ', joinedRoom);
259
+ // }, [joinedRoom]);
260
260
261
261
function joinRoom ( ) {
262
262
dispatch ( changeRoom ( roomCode ) ) ;
0 commit comments