File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ import {
13
13
addChild ,
14
14
changeFocus ,
15
15
deleteChild ,
16
- changePosition
16
+ changePosition ,
17
+ resetState
17
18
} from '../../redux/reducers/slice/appStateSlice' ;
18
19
import {
19
20
setRoomCode ,
@@ -136,7 +137,6 @@ const RoomsContainer = () => {
136
137
//edge case: if userList is not empty, reset it to empty array
137
138
if ( userList . length !== 0 ) dispatch ( setUserList ( [ ] ) ) ;
138
139
handleUserEnteredRoom ( roomCode ) ;
139
-
140
140
dispatch ( setRoomCode ( roomCode ) ) ; //?
141
141
dispatch ( setUserJoined ( true ) ) ; //setting joined room to true for rendering leave room button
142
142
}
@@ -145,6 +145,7 @@ const RoomsContainer = () => {
145
145
let socket = getSocket ( ) ;
146
146
if ( socket ) {
147
147
socket . disconnect ( ) ; //disconnecting socket from server
148
+ console . log ( socket ) ;
148
149
socket = null ;
149
150
console . log ( 'user leaves the room' ) ;
150
151
}
@@ -153,6 +154,7 @@ const RoomsContainer = () => {
153
154
dispatch ( setUserName ( '' ) ) ;
154
155
dispatch ( setUserList ( [ ] ) ) ;
155
156
dispatch ( setUserJoined ( false ) ) ; //setting joined to false so join room UI appear
157
+ dispatch ( resetState ( '' ) ) ;
156
158
}
157
159
158
160
//checking empty input field (not including spaces)
Original file line number Diff line number Diff line change @@ -16,10 +16,11 @@ import config from '../../../config';
16
16
let socket = null ;
17
17
18
18
export const initializeSocket = ( ) => {
19
- if ( socket ) socket . disconnect ( ) ;
19
+ if ( socket ) socket . connect ( ) ;
20
20
if ( ! socket ) {
21
21
socket = io ( config . API_BASE_URL , { transports : [ 'websocket' ] } ) ;
22
22
console . log ( 'A user connected' ) ;
23
+ console . log ( 'socket:' , socket ) ;
23
24
}
24
25
} ;
25
26
Original file line number Diff line number Diff line change @@ -163,15 +163,24 @@ io.on('connection', (client) => {
163
163
164
164
//disconnecting functionality
165
165
client . on ( 'disconnecting' , ( ) => {
166
- // the client.rooms Set contains at least the socket ID
167
166
const roomCode = Array . from ( client . rooms ) [ 1 ] ; //grabbing current room client was in when disconnecting
167
+ const userList = Object . keys ( roomLists [ roomCode ] ) ; //[ bHhFDmzPGam, mqri45c94E3 ] order is not perserved?
168
+ const hostID = userList [ 0 ] ;
169
+ // the client.rooms Set contains at least the socket ID
170
+ console . log ( `${ client . id } will be leaving the room` ) ;
171
+ console . log ( client . id === hostID ) ;
172
+ console . log ( roomLists [ roomCode ] ) ;
168
173
delete roomLists [ roomCode ] [ client . id ] ;
174
+ console . log ( roomLists [ roomCode ] ) ;
169
175
//if room empty, delete room from room list
170
176
if ( ! Object . keys ( roomLists [ roomCode ] ) . length ) {
171
177
delete roomLists [ roomCode ] ;
172
178
} else {
173
179
//else emit updated user list
174
- io . to ( roomCode ) . emit ( 'updateUserList' , roomLists [ roomCode ] ) ;
180
+ io . to ( roomCode ) . emit (
181
+ 'updateUserList' ,
182
+ Object . values ( roomLists [ roomCode ] )
183
+ ) ;
175
184
}
176
185
} ) ;
177
186
You can’t perform that action at this time.
0 commit comments