@@ -105,22 +105,24 @@ io.on('connection', (client) => {
105
105
} ) ;
106
106
107
107
//when user Joined a room
108
- client . on ( 'joining' , ( userName , roomCode ) => {
109
- client . join ( roomCode ) ; //client joining a room
108
+ client . on ( 'joining' , ( userName : string , roomCode : string ) => {
110
109
//if room exists, get state from host
111
110
if ( roomLists [ roomCode ] ) {
112
111
let hostID = Object . keys ( roomLists [ roomCode ] ) [ 0 ] ;
113
112
console . log ( 'back requesting state from host' ) ;
114
113
console . log ( 'host username:' , roomLists [ roomCode ] [ hostID ] ) ;
115
114
io . to ( roomLists [ roomCode ] [ hostID ] ) . emit ( 'requesting state from host' ) ;
116
115
client . on ( 'state from host' , ( state ) => {
117
- io . to ( client . id ) . emit ( 'new state from back ' , state ) ;
116
+ io . to ( client . id ) . emit ( 'back emitting state from host ' , state ) ;
118
117
} ) ;
119
118
//if no room exist, create new room in server
120
119
} else if ( ! roomLists [ roomCode ] ) {
121
120
roomLists [ roomCode ] = { } ;
122
121
}
123
122
roomLists [ roomCode ] [ client . id ] = userName ; // add user into the room with id: userName
123
+
124
+ client . join ( roomCode ) ; //client joining a room
125
+
124
126
console . log ( 'back emitting new user list' ) ;
125
127
io . to ( roomCode ) . emit ( 'updateUserList' , roomLists [ roomCode ] ) ; //send the message to all clients in room
126
128
0 commit comments