From 53c6c2bc30d7c896a64553ce2c807e95cbe93804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 29 Sep 2020 17:24:16 +0200 Subject: [PATCH] Fixing benchmark --- back/src/Controller/IoSocketController.ts | 18 ++++++------------ back/src/Model/Websocket/ExSocketInterface.ts | 1 - benchmark/index.ts | 9 +++++++-- front/src/Connexion/RoomConnection.ts | 4 ++-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index dc116616..c8753371 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -244,14 +244,10 @@ export class IoSocketController { //leave room this.leaveRoom(Client); - //leave webrtc room - //socket.leave(Client.webRtcRoomId); - //delete all socket information - delete Client.webRtcRoomId; - delete Client.roomId; + /*delete Client.roomId; delete Client.token; - delete Client.position; + delete Client.position;*/ } catch (e) { console.error('An error occurred on "disconnect"'); console.error(e); @@ -308,7 +304,7 @@ export class IoSocketController { } //leave previous room - this.leaveRoom(Client); + //this.leaveRoom(Client); // Useless now, there is only one room per connection //join new previous room const world = this.joinRoom(Client, roomId, ProtobufUtils.toPointInterface(message.getPosition() as PositionMessage)); @@ -567,7 +563,7 @@ export class IoSocketController { //Client.leave(Client.roomId); } finally { this.nbClientsPerRoomGauge.dec({ room: Client.roomId }); - delete Client.roomId; + //delete Client.roomId; } } } @@ -694,8 +690,6 @@ export class IoSocketController { return; }*/ - // TODO: joinWebRtcRoom will be trigerred twice when joining the first time! Maybe we should fix the GROUP constructor to trigger only one event -console.log('joinWebRtcRoom FOR '+user.socket.name+" "+user.socket.userId); for (const otherUser of group.getUsers()) { if (user === otherUser) { continue; @@ -712,7 +706,7 @@ console.log('joinWebRtcRoom FOR '+user.socket.name+" "+user.socket.userId); if (!user.socket.disconnecting) { user.socket.send(serverToClientMessage1.serializeBinary().buffer, true); - console.log('Sending webrtcstart initiator to '+user.socket.userId) + //console.log('Sending webrtcstart initiator to '+user.socket.userId) } const webrtcStartMessage2 = new WebRtcStartMessage(); @@ -725,7 +719,7 @@ console.log('joinWebRtcRoom FOR '+user.socket.name+" "+user.socket.userId); if (!otherUser.socket.disconnecting) { otherUser.socket.send(serverToClientMessage2.serializeBinary().buffer, true); - console.log('Sending webrtcstart to '+otherUser.socket.userId) + //console.log('Sending webrtcstart to '+otherUser.socket.userId) } } diff --git a/back/src/Model/Websocket/ExSocketInterface.ts b/back/src/Model/Websocket/ExSocketInterface.ts index 46c4b787..00aeadb7 100644 --- a/back/src/Model/Websocket/ExSocketInterface.ts +++ b/back/src/Model/Websocket/ExSocketInterface.ts @@ -7,7 +7,6 @@ import {WebSocket} from "uWebSockets.js" export interface ExSocketInterface extends WebSocket, Identificable { token: string; roomId: string; - webRtcRoomId: string|undefined; userId: number; // A temporary (autoincremented) identifier for this user userUuid: string; // A unique identifier for this user name: string; diff --git a/benchmark/index.ts b/benchmark/index.ts index ebf58c6a..af209581 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -1,4 +1,5 @@ -import {RoomConnection} from "../front/src/Connexion/Connection"; +import {RoomConnection} from "../front/src/Connexion/RoomConnection"; +import {connectionManager} from "../front/src/Connexion/ConnectionManager"; import * as WebSocket from "ws" function sleep(ms) { @@ -10,7 +11,8 @@ RoomConnection.setWebsocketFactory((url: string) => { }); async function startOneUser(): Promise { - const connection = await RoomConnection.createConnection('foo', ['male3']); + const connection = await connectionManager.connectToRoomSocket(); + connection.emitPlayerDetailsMessage('foo', ['male3']); await connection.joinARoom('global__maps.workadventure.localhost/Floor0/floor0', 783, 170, 'down', false, { top: 0, @@ -43,6 +45,9 @@ async function startOneUser(): Promise { } (async () => { + + //await connectionManager.init(); + for (let userNo = 0; userNo < 40; userNo++) { startOneUser(); // Wait 0.5s between adding users diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index e64164b8..526ce54c 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -61,7 +61,7 @@ export class RoomConnection implements RoomConnection { this.socket.binaryType = 'arraybuffer'; this.socket.onopen = (ev) => { - console.log('WS connected'); + //console.log('WS connected'); }; this.socket.onmessage = (messageEvent) => { @@ -143,7 +143,7 @@ export class RoomConnection implements RoomConnection { public emitPlayerDetailsMessage(userName: string, characterLayersSelected: string[]) { const message = new SetPlayerDetailsMessage(); - message.setName(name); + message.setName(userName); message.setCharacterlayersList(characterLayersSelected); const clientToServerMessage = new ClientToServerMessage();