2020-09-29 17:24:16 +02:00
|
|
|
import {RoomConnection} from "../front/src/Connexion/RoomConnection";
|
|
|
|
import {connectionManager} from "../front/src/Connexion/ConnectionManager";
|
2020-09-28 18:52:54 +02:00
|
|
|
import * as WebSocket from "ws"
|
2020-09-18 17:01:45 +02:00
|
|
|
|
2020-12-03 17:19:56 +01:00
|
|
|
let userMovedCount = 0;
|
2020-10-21 14:55:18 +02:00
|
|
|
|
2020-09-18 17:01:45 +02:00
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
|
2020-09-29 17:12:28 +02:00
|
|
|
RoomConnection.setWebsocketFactory((url: string) => {
|
2020-09-28 18:52:54 +02:00
|
|
|
return new WebSocket(url);
|
|
|
|
});
|
|
|
|
|
2020-09-18 17:01:45 +02:00
|
|
|
async function startOneUser(): Promise<void> {
|
2020-10-21 14:55:18 +02:00
|
|
|
await connectionManager.anonymousLogin(true);
|
2020-12-03 17:19:56 +01:00
|
|
|
const onConnect = await connectionManager.connectToRoomSocket(process.env.ROOM_ID ? process.env.ROOM_ID : '_/global/maps.workadventure.localhost/Floor0/floor0.json', 'TEST', ['male3'],
|
2020-10-21 14:55:18 +02:00
|
|
|
{
|
|
|
|
x: 783,
|
|
|
|
y: 170
|
|
|
|
}, {
|
|
|
|
top: 0,
|
|
|
|
bottom: 200,
|
|
|
|
left: 500,
|
|
|
|
right: 800
|
2021-07-29 15:53:27 +02:00
|
|
|
}, null);
|
2020-10-21 14:55:18 +02:00
|
|
|
|
2020-12-03 17:19:56 +01:00
|
|
|
const connection = onConnect.connection;
|
|
|
|
|
|
|
|
connection.onUserMoved(() => {
|
|
|
|
userMovedCount++;
|
|
|
|
})
|
|
|
|
|
2020-09-18 17:01:45 +02:00
|
|
|
console.log(connection.getUserId());
|
|
|
|
|
|
|
|
let angle = Math.random() * Math.PI * 2;
|
|
|
|
|
|
|
|
for (let i = 0; i < 100; i++) {
|
|
|
|
const x = Math.floor(320 + 1472/2 * (1 + Math.sin(angle)));
|
|
|
|
const y = Math.floor(200 + 1090/2 * (1 + Math.cos(angle)));
|
|
|
|
|
|
|
|
connection.sharePosition(x, y, 'down', true, {
|
|
|
|
top: y - 200,
|
|
|
|
bottom: y + 200,
|
|
|
|
left: x - 320,
|
|
|
|
right: x + 320
|
|
|
|
})
|
|
|
|
|
|
|
|
angle += 0.05;
|
|
|
|
|
|
|
|
await sleep(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
await sleep(10000);
|
|
|
|
connection.closeConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
2020-09-30 12:12:24 +02:00
|
|
|
connectionManager.initBenchmark();
|
2020-09-29 17:24:16 +02:00
|
|
|
|
2020-12-04 15:13:46 +01:00
|
|
|
const promises = [];
|
2020-09-29 17:24:16 +02:00
|
|
|
|
2020-10-01 15:55:23 +02:00
|
|
|
for (let userNo = 0; userNo < 160; userNo++) {
|
2020-12-04 15:13:46 +01:00
|
|
|
const promise = startOneUser();
|
|
|
|
promises.push(promise);
|
2020-09-18 17:01:45 +02:00
|
|
|
// Wait 0.5s between adding users
|
2020-10-01 15:55:23 +02:00
|
|
|
await sleep(125);
|
2020-09-18 17:01:45 +02:00
|
|
|
}
|
2020-12-03 17:19:56 +01:00
|
|
|
|
2020-12-04 15:13:46 +01:00
|
|
|
await Promise.all(promises);
|
|
|
|
console.log('User moved count: '+userMovedCount);
|
2020-09-18 17:01:45 +02:00
|
|
|
})();
|