import { roomList, createRoom, joinRoom } from "./lobbyapi.mjs"; import Player from "./wsplayer.mjs"; async function createSession(playerCount) { // 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 ); // 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 ); players.push(player); } return players; } createSession(4);