@@ -119,15 +119,30 @@ io.on('connection', (client) => {
119
119
//when user Joined a room
120
120
client . on ( 'joining' , ( userName , roomCode ) => {
121
121
client . join ( roomCode ) ;
122
- if ( ! roomLists [ roomCode ] ) roomLists [ roomCode ] = { } ; //if no room exist, create new room in server
122
+ if ( ! roomLists [ roomCode ] ) {
123
+ roomLists [ roomCode ] = { } ;
124
+ } //if no room exist, create new room in server
123
125
roomLists [ roomCode ] [ client . id ] = userName ; // add user into the room with id: userName
124
- io . in ( roomCode ) . emit ( 'updateUserList' , roomLists [ roomCode ] ) ; //send the message to all clients in room
126
+ console . log ( 'back emitting new user list' ) ;
127
+ client . in ( roomCode ) . emit ( 'updateUserList' , roomLists [ roomCode ] ) ; //send the message to all clients in room
125
128
console . log ( 'full room lists' , roomLists ) ;
126
129
console . log ( `${ userName } joined room ${ roomCode } ` ) ;
127
130
console . log (
128
131
`back sent User list of room ${ roomCode } : ` ,
129
132
roomLists [ roomCode ]
130
133
) ;
134
+
135
+ if ( roomLists [ roomCode ] ) {
136
+ //if room exists, get state from host
137
+ console . log ( 'back requesting state from host' ) ;
138
+ client . in ( roomCode ) . emit ( 'requesting state from host' , roomCode ) ;
139
+ // client.on('state from host', (state) => {
140
+ // client.to(client.id).emit('state from host', state);
141
+ // });
142
+ client . on ( 'state from host' , ( roomCode ) => {
143
+ console . log ( 'Receiving roomcode from front end host' , roomCode ) ;
144
+ } ) ;
145
+ }
131
146
} ) ;
132
147
133
148
client . on ( 'disconnecting' , ( ) => {
0 commit comments