Change to update world by scene and room id
This commit is contained in:
parent
58b65030bd
commit
8a91190d8c
2 changed files with 55 additions and 25 deletions
47
back/src/Model/Websocket/ExtRooms.ts
Normal file
47
back/src/Model/Websocket/ExtRooms.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import {ExtRoomsInterface} from "./ExtRoomsInterface";
|
||||
import socketIO = require('socket.io');
|
||||
import {ExSocketInterface} from "./ExSocketInterface";
|
||||
import {MessageUserPosition} from "./MessageUserPosition";
|
||||
import {World} from "_Model/World";
|
||||
|
||||
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.userId,
|
||||
roomId: socket.roomId,
|
||||
position: socket.position,
|
||||
name: socket.name,
|
||||
character: socket.character,
|
||||
};
|
||||
let dataArray = <any>[];
|
||||
if (mapPositionUserByRoom.get(data.roomId)) {
|
||||
dataArray = mapPositionUserByRoom.get(data.roomId);
|
||||
dataArray.push(data);
|
||||
} else {
|
||||
dataArray = [data];
|
||||
}
|
||||
mapPositionUserByRoom.set(data.roomId, dataArray);
|
||||
}
|
||||
rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom);
|
||||
}
|
||||
|
||||
export {
|
||||
RefreshUserPositionFunction
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue