From fb8d7b5d599d29a0ac802b2dc0ddf576d6f725ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 19 May 2020 19:53:26 +0200 Subject: [PATCH] Removing dead code --- back/src/Controller/IoSocketController.ts | 41 ----------------- back/src/Model/Websocket/ExtRooms.ts | 44 ------------------- back/src/Model/Websocket/ExtRoomsInterface.ts | 6 --- 3 files changed, 91 deletions(-) delete mode 100644 back/src/Model/Websocket/ExtRooms.ts delete mode 100644 back/src/Model/Websocket/ExtRoomsInterface.ts diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 63440d24..292db31f 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -5,8 +5,6 @@ import {MessageUserPosition, Point} from "../Model/Websocket/MessageUserPosition import {ExSocketInterface} from "../Model/Websocket/ExSocketInterface"; //TODO fix import by "_Model/.." import Jwt, {JsonWebTokenError} from "jsonwebtoken"; import {SECRET_KEY, MINIMUM_DISTANCE, GROUP_RADIUS} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..." -import {ExtRooms, RefreshUserPositionFunction} from "../Model/Websocket/ExtRooms"; -import {ExtRoomsInterface} from "../Model/Websocket/ExtRoomsInterface"; import {World} from "../Model/World"; import {Group} from "_Model/Group"; import {UserInterface} from "_Model/UserInterface"; @@ -58,7 +56,6 @@ export class IoSocketController { });*/ this.ioConnection(); - this.shareUsersPosition(); } private sendUpdateGroupEvent(group: Group): void { @@ -311,22 +308,6 @@ export class IoSocketController { }); } - refreshUserPosition(Client : ExSocketInterface) { - //refresh position of all user in all rooms in real time - let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface); - if (!rooms.refreshUserPosition) { - rooms.refreshUserPosition = RefreshUserPositionFunction; - } - rooms.refreshUserPosition(rooms, this.Io); - - // update position in the world - let world = this.Worlds.get(Client.roomId); - if (!world) { - return; - } - world.updatePosition(Client, Client.position); - } - //Hydrate and manage error hydratePositionReceive(message: any): Point | Error { try { @@ -356,28 +337,6 @@ export class IoSocketController { ... ] **/ - seTimeOutInProgress: any = null; - - shareUsersPosition() { - if (this.seTimeOutInProgress) { - clearTimeout(this.seTimeOutInProgress); - } - //send for each room, all data of position user - let arrayMap = (this.Io.sockets.adapter.rooms as ExtRooms).userPositionMapByRoom; - if (!arrayMap) { - this.seTimeOutInProgress = setTimeout(() => { - this.shareUsersPosition(); - }, 10); - return; - } - arrayMap.forEach((value: any) => { - let roomId = value[0]; - this.Io.in(roomId).emit(SockerIoEvent.USER_POSITION, value); - }); - this.seTimeOutInProgress = setTimeout(() => { - this.shareUsersPosition(); - }, 10); - } //connected user connectedUser(userId: string, group: Group) { diff --git a/back/src/Model/Websocket/ExtRooms.ts b/back/src/Model/Websocket/ExtRooms.ts deleted file mode 100644 index b5493fdb..00000000 --- a/back/src/Model/Websocket/ExtRooms.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {ExtRoomsInterface} from "./ExtRoomsInterface"; -import socketIO = require('socket.io'); -import {ExSocketInterface} from "./ExSocketInterface"; - -export class ExtRooms implements ExtRoomsInterface{ - userPositionMapByRoom: any; - refreshUserPosition: any; - Worlds: any; - - [room: string]: SocketIO.Room; -} - -let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server) { - let clients = Io.clients(); - let socketsKey = Object.keys(Io.clients().sockets); - - //create mapping with all users in all rooms - let mapPositionUserByRoom = new Map(); - for (let i = 0; i < socketsKey.length; i++) { - let socket = clients.sockets[socketsKey[i]] as ExSocketInterface; - if (!socket.position) { - continue; - } - let data = { - userId: socket.id, - position: socket.position, - name: socket.name, - character: socket.character, - }; - let dataArray = []; - if (mapPositionUserByRoom.get(socket.roomId)) { - dataArray = mapPositionUserByRoom.get(socket.roomId); - dataArray.push(data); - } else { - dataArray = [data]; - } - mapPositionUserByRoom.set(socket.roomId, dataArray); - } - rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom); -}; - -export { - RefreshUserPositionFunction -}; diff --git a/back/src/Model/Websocket/ExtRoomsInterface.ts b/back/src/Model/Websocket/ExtRoomsInterface.ts deleted file mode 100644 index a71fcbf9..00000000 --- a/back/src/Model/Websocket/ExtRoomsInterface.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {Rooms} from "socket.io"; - -export interface ExtRoomsInterface extends Rooms{ - userPositionMapByRoom: any; - refreshUserPosition: any; -} \ No newline at end of file