From: gparant Date: Fri, 8 May 2020 09:54:47 +0000 (+0200) Subject: Fix shares information to enter into Webrtc room. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=41f5b5a1f68644de738b140c4783e9a845f4d685;p=libreadventure.git 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. --- diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index d253cc9..bd3f9bc 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -91,9 +91,6 @@ export class IoSocketController { 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); @@ -192,8 +189,8 @@ export class IoSocketController { if (this.Io.sockets.adapter.rooms[roomId].length < 2 || this.Io.sockets.adapter.rooms[roomId].length >= 4) { return; } - let clients: Array = Object.values(this.Io.sockets.sockets); - + let clients: Array = 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) => { @@ -228,7 +225,7 @@ export class IoSocketController { if (!rooms.refreshUserPosition) { rooms.refreshUserPosition = RefreshUserPositionFunction; } - rooms.refreshUserPosition(rooms, this.Io); + rooms.refreshUserPosition(rooms, this.Io, this.World); } //Hydrate and manage error diff --git a/back/src/Model/Websocket/ExtRoom.ts b/back/src/Model/Websocket/ExtRoom.ts index a1b2cb6..5ad8128 100644 --- a/back/src/Model/Websocket/ExtRoom.ts +++ b/back/src/Model/Websocket/ExtRoom.ts @@ -1,6 +1,8 @@ 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; @@ -9,7 +11,7 @@ export class ExtRooms implements ExtRoomsInterface{ [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); @@ -35,6 +37,10 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server 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); }