@gameye/sdk
Version:
Node.js SDK for Gameye
53 lines • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const uuid = require("uuid");
const gameye_1 = require("../clients/gameye");
const selectors = require("../selectors");
const utils_1 = require("../utils");
main();
/*
You must set the GAMEYE_API_TOKEN environment variable to use this !
*/
async function main() {
// tslint:disable: no-console
const gameyeClient = new gameye_1.GameyeClient();
const matchSubscription = await gameyeClient.subscribeMatch();
const matchKey = uuid();
let match = null;
console.log(`starting match ${matchKey}`);
console.log(`---`);
await gameyeClient.commandStartMatch(matchKey, "csgo-dem", ["frankfurt"], "bots", { maxRounds: 2 });
/*
wait for the match to appear in the state
*/
while (!match) {
const state = await utils_1.streamWait(matchSubscription);
match = selectors.selectMatchItem(state, matchKey);
}
const statisticSubscription = await gameyeClient.subscribeStatistic(matchKey);
statisticSubscription.on("data", (state) => {
const round = selectors.getRound(state);
console.log(`Round: ${round}`);
console.log(`---`);
const players = selectors.selectPlayerList(state);
for (const player of players) {
console.log(`${player.name} has ${player.statistic.kill} kills and ${player.statistic.death} deaths`);
}
console.log(`---`);
});
/*
wait for the match to dissappear from the
state (takes about 2 to 3 minutes)
*/
while (match) {
const state = await utils_1.streamWait(matchSubscription);
match = selectors.selectMatchItem(state, matchKey);
}
console.log(`match ${matchKey} finished`);
console.log(`---`);
matchSubscription.destroy();
await utils_1.whenFinished(matchSubscription);
statisticSubscription.destroy();
await utils_1.whenFinished(statisticSubscription);
}
//# sourceMappingURL=bots.js.map