return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message}));
}
- // update position in the worl
- this.World.updatePosition(messageUserPosition);
-
// sending to all clients in room except sender
this.saveUserInformation((socket as ExSocketInterface), messageUserPosition);
if (this.Io.sockets.adapter.rooms[roomId].length < 2 || this.Io.sockets.adapter.rooms[roomId].length >= 4) {
return;
}
- let clients: Array<any> = Object.values(this.Io.sockets.sockets);
-
+ let clients: Array<ExSocketInterface> = Object.values(this.Io.sockets.sockets)
+ .filter((client: ExSocketInterface) => client.webRtcRoomId && client.webRtcRoomId === roomId);
//send start at one client to initialise offer webrtc
//send all users in room to create PeerConnection in front
clients.forEach((client: ExSocketInterface, index: number) => {
if (!rooms.refreshUserPosition) {
rooms.refreshUserPosition = RefreshUserPositionFunction;
}
- rooms.refreshUserPosition(rooms, this.Io);
+ rooms.refreshUserPosition(rooms, this.Io, this.World);
}
//Hydrate and manage error
import {ExtRoomsInterface} from "./ExtRoomsInterface";
import socketIO = require('socket.io');
-import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
+import {ExSocketInterface} from "./ExSocketInterface";
+import {MessageUserPosition} from "./MessageUserPosition";
+import {World} from "_Model/World";
export class ExtRooms implements ExtRoomsInterface{
userPositionMapByRoom: any;
[room: string]: SocketIO.Room;
}
-let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server) {
+let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server, World : World) {
let clients = Io.clients();
let socketsKey = Object.keys(Io.clients().sockets);
dataArray = [data];
}
mapPositionUserByRoom.set(data.roomId, dataArray);
+
+ // update position in the worl
+ let messageUserPosition = new MessageUserPosition(data);
+ World.updatePosition(messageUserPosition);
}
rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom);
}