colyseus-server-stress-tester/client.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-08-04 09:56:05 +08:00
import * as Colyseus from "colyseus.js";
import { logError, writeLine } from "./logger.js";
import { markReceive } from "./received-packages.js";
export class Client {
client;
room;
index;
packageIndex = 0;
constructor(index) {
this.index = index;
}
async joinRoom() {
this.client = new Colyseus.Client('wss://api-meta.sequenxe.com/socket');
this.room = await this.client.joinOrCreate("my_room");
this.room.onStateChange((state) => {
if (this.index !== 0) {
return;
}
markReceive();
writeLine(state);
});
this.room.onError((code, message) => {
logError('error:', code, message);
})
}
testOnce() {
this.room.send("updatePlayer", {
x: +Math.random().toFixed(1),
y: +Math.random().toFixed(1),
z: +Math.random().toFixed(1),
rotationX: +Math.random().toFixed(1),
rotationY: +Math.random().toFixed(1),
rotationZ: +Math.random().toFixed(1),
animation: Math.random().toFixed(1),
nickname: Math.random().toFixed(1),
characterKey: `${this.index}#${this.packageIndex++}`,
});
}
}