Fix shares information to enter into Webrtc room.

- Refactor share position in world class.
- Update selects a client to send information about connecting WebRtc room.
This commit is contained in:
gparant 2020-05-08 11:54:47 +02:00
parent 16cf33755c
commit 41f5b5a1f6
2 changed files with 11 additions and 8 deletions

View File

@ -91,9 +91,6 @@ export class IoSocketController {
return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message})); 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 // sending to all clients in room except sender
this.saveUserInformation((socket as ExSocketInterface), messageUserPosition); this.saveUserInformation((socket as ExSocketInterface), messageUserPosition);
@ -192,8 +189,8 @@ export class IoSocketController {
if (this.Io.sockets.adapter.rooms[roomId].length < 2 || this.Io.sockets.adapter.rooms[roomId].length >= 4) { if (this.Io.sockets.adapter.rooms[roomId].length < 2 || this.Io.sockets.adapter.rooms[roomId].length >= 4) {
return; 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 start at one client to initialise offer webrtc
//send all users in room to create PeerConnection in front //send all users in room to create PeerConnection in front
clients.forEach((client: ExSocketInterface, index: number) => { clients.forEach((client: ExSocketInterface, index: number) => {
@ -228,7 +225,7 @@ export class IoSocketController {
if (!rooms.refreshUserPosition) { if (!rooms.refreshUserPosition) {
rooms.refreshUserPosition = RefreshUserPositionFunction; rooms.refreshUserPosition = RefreshUserPositionFunction;
} }
rooms.refreshUserPosition(rooms, this.Io); rooms.refreshUserPosition(rooms, this.Io, this.World);
} }
//Hydrate and manage error //Hydrate and manage error

View File

@ -1,6 +1,8 @@
import {ExtRoomsInterface} from "./ExtRoomsInterface"; import {ExtRoomsInterface} from "./ExtRoomsInterface";
import socketIO = require('socket.io'); 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{ export class ExtRooms implements ExtRoomsInterface{
userPositionMapByRoom: any; userPositionMapByRoom: any;
@ -9,7 +11,7 @@ export class ExtRooms implements ExtRoomsInterface{
[room: string]: SocketIO.Room; [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 clients = Io.clients();
let socketsKey = Object.keys(Io.clients().sockets); let socketsKey = Object.keys(Io.clients().sockets);
@ -35,6 +37,10 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
dataArray = [data]; dataArray = [data];
} }
mapPositionUserByRoom.set(data.roomId, dataArray); mapPositionUserByRoom.set(data.roomId, dataArray);
// update position in the worl
let messageUserPosition = new MessageUserPosition(data);
World.updatePosition(messageUserPosition);
} }
rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom); rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom);
} }