Fixing disconnection taking ~15 seconds

Most of the time, sending a disconnect event to one of the players is enough (the player will close the connection
which will be shut for the other player).
However! In the rare case where the WebRTC connection is not yet established, if we close the connection on one of the player,
the other player will try connecting until a timeout happens (during this time, the circle with the name is displayed for nothing).

So now, we send disconnection event to every body (not only the people in the group, but also to the person leaving the group)
This commit is contained in:
David Négrier 2020-06-05 13:07:18 +02:00
parent b82b13e351
commit 96c5d92c46
3 changed files with 57 additions and 17 deletions

View file

@ -7,6 +7,7 @@ import {SetPlayerDetailsMessage} from "./Messages/SetPlayerDetailsMessage";
const SocketIo = require('socket.io-client');
import Socket = SocketIOClient.Socket;
import {PlayerAnimationNames} from "./Phaser/Player/Animation";
import {UserSimplePeer} from "./WebRtc/SimplePeer";
enum EventMessage{
@ -97,6 +98,15 @@ export interface GroupCreatedUpdatedMessageInterface {
groupId: string
}
export interface WebRtcStartMessageInterface {
roomId: string,
clients: UserSimplePeer[]
}
export interface WebRtcDisconnectMessageInterface {
userId: string
}
export interface ConnectionInterface {
socket: Socket|null;
token: string|null;
@ -116,9 +126,9 @@ export interface ConnectionInterface {
receiveWebrtcSignal(callBack: Function): void;
receiveWebrtcStart(callBack: Function): void;
receiveWebrtcStart(callBack: (message: WebRtcStartMessageInterface) => void): void;
disconnectMessage(callBack: Function): void;
disconnectMessage(callBack: (message: WebRtcDisconnectMessageInterface) => void): void;
}
export class Connection implements ConnectionInterface {
@ -277,7 +287,7 @@ export class Connection implements ConnectionInterface {
});
}
receiveWebrtcStart(callback: Function) {
receiveWebrtcStart(callback: (message: WebRtcStartMessageInterface) => void) {
this.getSocket().on(EventMessage.WEBRTC_START, callback);
}
@ -305,7 +315,7 @@ export class Connection implements ConnectionInterface {
});
}
disconnectMessage(callback: Function): void {
disconnectMessage(callback: (message: WebRtcDisconnectMessageInterface) => void): void {
this.getSocket().on(EventMessage.WEBRTC_DISCONNECT, callback);
}
}