mlp-server-tools/tools/test-draft/index.mjs
Hamcha 01f9b3cfd4
All checks were successful
continuous-integration/drone/push Build is passing
Fix some scripts
2019-07-04 16:49:14 +02:00

52 lines
1.2 KiB
JavaScript

import { roomList, createRoom, joinRoom } from "./lobbyapi.mjs";
import Player from "./wsplayer.mjs";
async function createSession(playerCount, sessionOptions) {
// Create room
const createResult = await createRoom("test script", "owner");
const roomID = createResult.data.room_id;
// Create owner player
const tp1 = new Player(
createResult.data.ws_url,
createResult.data.auth_token
);
const info = await tp1.connect();
// List rooms and check that ours is available
const listResult = await roomList();
const roomFound =
listResult.data.rooms.filter(x => x.id == roomID).length > 0;
if (!roomFound) {
throw `room ${roomID} not found in list after creation`;
}
// Create other players
let players = [tp1];
for (let i = 1; i < playerCount; i++) {
// Join the room
const joinResult = await joinRoom(roomID, `guest${i}`);
// Create player
const player = new Player(
joinResult.data.ws_url,
joinResult.data.auth_token
);
const info = await player.connect();
console.log(info.backlog);
players.push(player);
}
return players;
}
async function main() {
try {
const players = await createSession(4);
} catch (e) {
console.error(e);
}
}
main();