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";
});*/
this.ioConnection();
- this.shareUsersPosition();
}
private sendUpdateGroupEvent(group: Group): void {
});
}
- 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 {
...
]
**/
- 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) {
+++ /dev/null
-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
-};