2019-07-03 15:52:29 +00:00
|
|
|
import { roomList, createRoom, joinRoom } from "./lobbyapi.mjs";
|
|
|
|
import Player from "./wsplayer.mjs";
|
|
|
|
|
2019-07-04 14:49:14 +00:00
|
|
|
async function createSession(playerCount, sessionOptions) {
|
2019-07-03 15:52:29 +00:00
|
|
|
// 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
|
|
|
|
);
|
2019-07-04 14:49:14 +00:00
|
|
|
const info = await tp1.connect();
|
2019-07-03 15:52:29 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
);
|
2019-07-04 14:49:14 +00:00
|
|
|
const info = await player.connect();
|
|
|
|
console.log(info.backlog);
|
2019-07-03 15:52:29 +00:00
|
|
|
players.push(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2019-07-04 14:49:14 +00:00
|
|
|
async function main() {
|
|
|
|
try {
|
|
|
|
const players = await createSession(4);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|