Fix some scripts
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Hamcha 2019-07-04 16:49:14 +02:00
parent e06b0b29a1
commit 01f9b3cfd4
3 changed files with 50 additions and 4 deletions

View File

@ -51,7 +51,7 @@ services:
image: moaorg/cardgage-lobby
environment:
- "JWT_KEY=this-is-a-test-key"
- "WSS_HOST=ws://192.168.22.23/api/room"
- "WSS_HOST=ws://192.168.20.20/api/room"
volumes:
- ".:/app"
depends_on:
@ -77,6 +77,7 @@ services:
draftbot:
container_name: draftbot
command: -debug.log
build:
context: "."
dockerfile: Dockerfile.run

View File

@ -1,7 +1,7 @@
import { roomList, createRoom, joinRoom } from "./lobbyapi.mjs";
import Player from "./wsplayer.mjs";
async function createSession(playerCount) {
async function createSession(playerCount, sessionOptions) {
// Create room
const createResult = await createRoom("test script", "owner");
const roomID = createResult.data.room_id;
@ -11,6 +11,7 @@ async function createSession(playerCount) {
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();
@ -32,10 +33,20 @@ async function createSession(playerCount) {
joinResult.data.ws_url,
joinResult.data.auth_token
);
const info = await player.connect();
console.log(info.backlog);
players.push(player);
}
return players;
}
createSession(4);
async function main() {
try {
const players = await createSession(4);
} catch (e) {
console.error(e);
}
}
main();

View File

@ -1,3 +1,37 @@
import WebSocket from "ws";
import { resolve } from "dns";
import { rejects } from "assert";
export default class Player {
constructor(wsURL, authToken) {}
constructor(wsURL, authToken) {
this.wsURL = wsURL;
this.authToken = authToken;
}
async connect() {
this.ws = new WebSocket(this.wsURL);
return new Promise((resolve, reject) => {
this.ws.on("message", data => {
this.ws.removeAllListeners("message");
this.ws.on("message", this._onMessage);
resolve(JSON.parse(data));
});
this.ws.on("open", () => {
this.send({
token: this.authToken
});
});
this.ws.on("close", () => reject("connection closed"));
});
}
send(data) {
const jsonData = JSON.stringify(data);
this.ws.send(jsonData);
}
_onMessage(msg) {
const data = JSON.parse(msg);
//TODO
}
}