Fix some scripts
All checks were successful
continuous-integration/drone/push Build is passing

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 image: moaorg/cardgage-lobby
environment: environment:
- "JWT_KEY=this-is-a-test-key" - "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: volumes:
- ".:/app" - ".:/app"
depends_on: depends_on:
@ -77,6 +77,7 @@ services:
draftbot: draftbot:
container_name: draftbot container_name: draftbot
command: -debug.log
build: build:
context: "." context: "."
dockerfile: Dockerfile.run dockerfile: Dockerfile.run

View file

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