Merge pull request #285 from thecodingmachine/fixdisconnect

Fixing disconnect triggering reconnect
This commit is contained in:
David Négrier 2020-10-01 17:20:55 +02:00 committed by GitHub
commit 8773989bbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 14 deletions

View file

@ -1,6 +1,6 @@
import Jwt from "jsonwebtoken";
import {ADMIN_API_TOKEN, ADMIN_API_URL, SECRET_KEY, URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
import { uuid } from 'uuidv4';
import { v4 } from 'uuid';
import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js";
import {BaseController} from "./BaseController";
import Axios from "axios";
@ -63,7 +63,7 @@ export class AuthenticateController extends BaseController {
mapUrlStart = data.mapUrlStart;
newUrl = this.getNewUrlOnAdminAuth(data)
} else {
userUuid = uuid();
userUuid = v4();
mapUrlStart = host.replace('api.', 'maps.') + URL_ROOM_STARTED;
newUrl = null;
}

View file

@ -1,6 +1,6 @@
import {App} from "../Server/sifrr.server";
import {uuid} from "uuidv4";
import {v4} from "uuid";
import {HttpRequest, HttpResponse} from "uWebSockets.js";
import {BaseController} from "./BaseController";
import { Readable } from 'stream'
@ -51,7 +51,7 @@ export class FileController extends BaseController {
})
try {
const audioMessageId = uuid();
const audioMessageId = v4();
const params = await res.formData({
onFile: (fieldname: string,

View file

@ -16,7 +16,7 @@ import {PointInterface} from "../Model/Websocket/PointInterface";
import {isWebRtcSignalMessageInterface} from "../Model/Websocket/WebRtcSignalMessage";
import {UserInGroupInterface} from "../Model/Websocket/UserInGroupInterface";
import {isItemEventMessageInterface} from "../Model/Websocket/ItemEventMessage";
import {uuid} from 'uuidv4';
import { v4 as uuidv4 } from 'uuid';
import {GroupUpdateInterface} from "_Model/Websocket/GroupUpdateInterface";
import {Movable} from "../Model/Movable";
import {
@ -135,7 +135,7 @@ export class IoSocketController {
if (ALLOW_ARTILLERY) {
return {
token,
userUuid: uuid()
userUuid: uuidv4()
}
} else {
throw new Error("In order to perform a load-testing test on this environment, you must set the ALLOW_ARTILLERY environment variable to 'true'");

View file

@ -1,7 +1,6 @@
import { World, ConnectCallback, DisconnectCallback } from "./World";
import { ConnectCallback, DisconnectCallback } from "./World";
import { User } from "./User";
import {PositionInterface} from "_Model/PositionInterface";
import {uuid} from "uuidv4";
import {Movable} from "_Model/Movable";
import {PositionNotifier} from "_Model/PositionNotifier";

View file

@ -36,10 +36,8 @@ export class ConsoleGlobalMessageManager {
}
initialise() {
try {
HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE);
}catch (err){
console.error(err);
for (const elem of document.getElementsByClassName(CLASS_CONSOLE_MESSAGE)) {
elem.remove();
}
const typeConsole = document.createElement('input');

View file

@ -10,7 +10,7 @@ interface LoginApiData {
}
class ConnectionManager {
private initPromise: Promise<LoginApiData> = Promise.reject();
private initPromise!: Promise<LoginApiData>;
private mapUrlStart: string|null = null;
private authToken:string|null = null;

View file

@ -43,6 +43,7 @@ export class RoomConnection implements RoomConnection {
private userId: number|null = null;
private listeners: Map<string, Function[]> = new Map<string, Function[]>();
private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any
private closed: boolean = false;
public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any
RoomConnection.websocketFactory = websocketFactory;
@ -157,6 +158,7 @@ export class RoomConnection implements RoomConnection {
public closeConnection(): void {
this.socket?.close();
this.closed = true;
}
private resolveJoinRoom!: (value?: (RoomJoinedMessageInterface | PromiseLike<RoomJoinedMessageInterface> | undefined)) => void;
@ -389,6 +391,9 @@ export class RoomConnection implements RoomConnection {
public onServerDisconnected(callback: (event: CloseEvent) => void): void {
this.socket.addEventListener('close', (event) => {
if (this.closed === true) {
return;
}
console.log('Socket closed with code '+event.code+". Reason: "+event.reason);
if (event.code === 1000) {
// Normal closure case

View file

@ -951,7 +951,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
});
const nextSceneKey = this.checkToExit();
if(nextSceneKey){
if (nextSceneKey) {
// We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map.
this.connection.closeConnection();
this.simplePeer.unregister();