workadventure/back/src/Model/Websocket/ExtRooms.ts
David Négrier 4de552437d Completely getting rid of "userid"
Previously, userid was generated by the "/login" route and passed along.
This commit completely removes the uuid "userid" (and disables the LoginController too and any Jwt check).

"userid" is replaced by the "socket id" of the connection.
So a user is now identified using a socket id, which is unique for a given connection.
2020-05-14 23:20:43 +02:00

46 lines
1.4 KiB
TypeScript

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,
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
};