Nextrek
Diff Revisions
1128
vs
1129
for /socketIO/index.js
|
@@ -134,19 +134,25 @@ |
134 |
134 |
|
}); |
135 |
135 |
|
|
136 |
136 |
|
|
137 |
|
- |
// customer forces operator to leave the room |
|
137 |
+ |
// leave the room |
138 |
138 |
|
socket.on(EVENTS.ROOM.LEAVE, (data) => { |
139 |
139 |
|
if (!user) { |
140 |
140 |
|
return |
141 |
141 |
|
} |
142 |
|
- |
|
143 |
|
- |
const hostRoom = Chat.leaveRoom(data.user, user); |
144 |
|
- |
socket.join(hostRoom); |
145 |
|
- |
|
146 |
|
- |
event = Chat.event(EVENTS.ROOM.JOIN, user); |
147 |
|
- |
io.to(hostRoom).emit(event.type, event.data); |
148 |
142 |
|
|
149 |
|
- |
console.log('join room', user.name, event.data); |
|
143 |
+ |
const host = data && data.user || user; |
|
144 |
+ |
const promises = Chat.leaveRoom(host, user); |
|
145 |
+ |
|
|
146 |
+ |
Promise.all(promises).then(guestSockets => { |
|
147 |
+ |
socket.leave(host.room); |
|
148 |
+ |
|
|
149 |
+ |
event = Chat.event(EVENTS.ROOM.LEAVE, user); |
|
150 |
+ |
io.to(host.room).emit(event.type, event.data); |
|
151 |
+ |
|
|
152 |
+ |
guestSockets.forEach(guestSocket => { |
|
153 |
+ |
guestSocket.leave(host.room); |
|
154 |
+ |
}); |
|
155 |
+ |
}); |
150 |
156 |
|
}); |
151 |
157 |
|
|
152 |
158 |
|
|
|
@@ -159,9 +165,19 @@ |
159 |
165 |
|
|
160 |
166 |
|
event = Chat.event(EVENTS.CONNECTION.CLOSE); |
161 |
167 |
|
io.to(user.room).emit(event.type, event.data); |
|
168 |
+ |
|
|
169 |
+ |
const promises = Chat.deleteUser(user); |
|
170 |
+ |
|
|
171 |
+ |
Promise.all(promises).then(guestSockets => { |
|
172 |
+ |
event = Chat.event(EVENTS.ROOM.LEAVE, user); |
|
173 |
+ |
io.to(user.room).emit(event.type, event.data); |
|
174 |
+ |
|
|
175 |
+ |
guestSockets.forEach(guestSocket => { |
|
176 |
+ |
guestSocket.leave(user.room); |
|
177 |
+ |
}); |
|
178 |
+ |
}); |
162 |
179 |
|
|
163 |
180 |
|
const userRole = user.role; |
164 |
|
- |
Chat.deleteUser(user); |
165 |
181 |
|
|
166 |
182 |
|
// send operators updated list to operators |
167 |
183 |
|
if (userRole === ROLES.OPERATOR) { |