Merge pull request #849 from thecodingmachine/unloadingFixes
improved the back to better handle ghost connexions
This commit is contained in:
commit
4b8a2aca34
@ -43,8 +43,13 @@ const roomManager: IRoomManagerServer = {
|
|||||||
if (room === null || user === null) {
|
if (room === null || user === null) {
|
||||||
if (message.hasJoinroommessage()) {
|
if (message.hasJoinroommessage()) {
|
||||||
socketManager.handleJoinRoom(call, message.getJoinroommessage() as JoinRoomMessage).then(({room: gameRoom, user: myUser}) => {
|
socketManager.handleJoinRoom(call, message.getJoinroommessage() as JoinRoomMessage).then(({room: gameRoom, user: myUser}) => {
|
||||||
|
if (call.writable) {
|
||||||
room = gameRoom;
|
room = gameRoom;
|
||||||
user = myUser;
|
user = myUser;
|
||||||
|
} else {
|
||||||
|
//Connexion may have been closed before the init was finished, so we have to manually disconnect the user.
|
||||||
|
socketManager.leaveRoom(gameRoom, myUser);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error('The first message sent MUST be of type JoinRoomMessage');
|
throw new Error('The first message sent MUST be of type JoinRoomMessage');
|
||||||
|
@ -81,6 +81,13 @@ export class SocketManager {
|
|||||||
//join new previous room
|
//join new previous room
|
||||||
const {room, user} = await this.joinRoom(socket, joinRoomMessage);
|
const {room, user} = await this.joinRoom(socket, joinRoomMessage);
|
||||||
|
|
||||||
|
if (!socket.writable) {
|
||||||
|
console.warn('Socket was aborted');
|
||||||
|
return {
|
||||||
|
room,
|
||||||
|
user
|
||||||
|
};
|
||||||
|
}
|
||||||
const roomJoinedMessage = new RoomJoinedMessage();
|
const roomJoinedMessage = new RoomJoinedMessage();
|
||||||
roomJoinedMessage.setTagList(joinRoomMessage.getTagList());
|
roomJoinedMessage.setTagList(joinRoomMessage.getTagList());
|
||||||
|
|
||||||
@ -96,7 +103,6 @@ export class SocketManager {
|
|||||||
|
|
||||||
const serverToClientMessage = new ServerToClientMessage();
|
const serverToClientMessage = new ServerToClientMessage();
|
||||||
serverToClientMessage.setRoomjoinedmessage(roomJoinedMessage);
|
serverToClientMessage.setRoomjoinedmessage(roomJoinedMessage);
|
||||||
console.log('SENDING MESSAGE roomJoinedMessage');
|
|
||||||
socket.write(serverToClientMessage);
|
socket.write(serverToClientMessage);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -264,8 +270,6 @@ export class SocketManager {
|
|||||||
debug('Room is empty. Deleting room "%s"', room.roomId);
|
debug('Room is empty. Deleting room "%s"', room.roomId);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
//delete Client.roomId;
|
|
||||||
//this.sockets.delete(Client.userId);
|
|
||||||
clientEventsEmitter.emitClientLeave(user.uuid, room.roomId);
|
clientEventsEmitter.emitClientLeave(user.uuid, room.roomId);
|
||||||
console.log('A user left');
|
console.log('A user left');
|
||||||
}
|
}
|
||||||
@ -415,10 +419,6 @@ export class SocketManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private joinWebRtcRoom(user: User, group: Group) {
|
private joinWebRtcRoom(user: User, group: Group) {
|
||||||
/*const roomId: string = "webrtcroom"+group.getId();
|
|
||||||
if (user.socket.webRtcRoomId === roomId) {
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for (const otherUser of group.getUsers()) {
|
for (const otherUser of group.getUsers()) {
|
||||||
if (user === otherUser) {
|
if (user === otherUser) {
|
||||||
|
Loading…
Reference in New Issue
Block a user