Removing dead code
authorDavid Négrier <d.negrier@thecodingmachine.com>
Tue, 19 May 2020 17:53:26 +0000 (19:53 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Tue, 19 May 2020 17:53:26 +0000 (19:53 +0200)
back/src/Controller/IoSocketController.ts
back/src/Model/Websocket/ExtRooms.ts [deleted file]
back/src/Model/Websocket/ExtRoomsInterface.ts [deleted file]

index 63440d24484f317061b7a4441d8fd9af732d0ceb..292db31ff8dc6940dccfa5422ef897b7e88d2d12 100644 (file)
@@ -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 (file)
index b5493fd..0000000
+++ /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 = <any>[];
-        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 (file)
index a71fcbf..0000000
+++ /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