|
|
@ -1,66 +1,13 @@
|
|
|
|
/* eslint-disable no-unused-vars, no-undef */
|
|
|
|
/* eslint-disable no-unused-vars, no-undef */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
class BingoGraphqlHelper {
|
|
|
|
* Returns the value of the url-param 'g'
|
|
|
|
|
|
|
|
* @returns {string}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getLobbyParam() {
|
|
|
|
|
|
|
|
let matches = window.location.href.match(/\??&?g=(\d+)/);
|
|
|
|
|
|
|
|
if (matches)
|
|
|
|
|
|
|
|
return matches[1];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* REturns the value of the r url param
|
|
|
|
|
|
|
|
* @returns {string}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getRoundParam() {
|
|
|
|
|
|
|
|
let matches = window.location.href.match(/\??&?r=(\d+)/);
|
|
|
|
|
|
|
|
if (matches)
|
|
|
|
|
|
|
|
return matches[1];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Spawns a notification when the window is inactive (hidden).
|
|
|
|
|
|
|
|
* @param body
|
|
|
|
|
|
|
|
* @param title
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function spawnNotification(body, title) {
|
|
|
|
|
|
|
|
if (Notification.permission !== 'denied' && document[getHiddenNames().hidden]) {
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
|
|
|
body: body,
|
|
|
|
|
|
|
|
icon: '/favicon.ico'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let n = new Notification(title, options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Submits the value of the username-input to set the username.
|
|
|
|
|
|
|
|
* @returns {Promise<Boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function submitUsername() {
|
|
|
|
|
|
|
|
let unameInput = document.querySelector('#input-username');
|
|
|
|
|
|
|
|
let username = unameInput.value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (username.length > 1 && username.length <= 30) {
|
|
|
|
|
|
|
|
return await setUsername(username);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('You need to provide a username (min. 2 characters, max. 30)!');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sets the username for a user
|
|
|
|
* Sets the username for a user
|
|
|
|
* @param username {String} - the username
|
|
|
|
* @param username {String} - the username
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function setUsername(username) {
|
|
|
|
static async setUsername(username) {
|
|
|
|
username = username.replace(/^\s+|\s+$/g, '');
|
|
|
|
username = username.replace(/^\s+|\s+$/g, '');
|
|
|
|
let uname = username.replace(/[\n\t👑🌟]|^\s+|\s+$/gu, '');
|
|
|
|
let uname = username.replace(/[\n\t👑🌟]|^\s+|\s+$/gu, '');
|
|
|
|
if (uname.length === username.length) {
|
|
|
|
if (uname.length === username.length) {
|
|
|
@ -80,6 +27,7 @@ async function setUsername(username) {
|
|
|
|
showError(response.errors[0].message);
|
|
|
|
showError(response.errors[0].message);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
showError(`Failed to submit username.`);
|
|
|
|
showError(`Failed to submit username.`);
|
|
|
|
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
console.error(response);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -89,38 +37,10 @@ async function setUsername(username) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Function that displays the ping in the console.
|
|
|
|
* Creates a lobby via the graphql endpoint
|
|
|
|
* @returns {Promise<number>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function ping() {
|
|
|
|
|
|
|
|
let start = new Date().getTime();
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query {
|
|
|
|
|
|
|
|
time
|
|
|
|
|
|
|
|
}`);
|
|
|
|
|
|
|
|
console.log(`Ping: ${(new Date().getTime()) - start} ms`);
|
|
|
|
|
|
|
|
return (new Date().getTime()) - start;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Joins a lobby or says to create one if none is found
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function joinLobby() {
|
|
|
|
|
|
|
|
if (getLobbyParam()) {
|
|
|
|
|
|
|
|
if (await submitUsername())
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('No lobby found. Please create one.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Creates a lobby and redirects to the lobby.
|
|
|
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function createLobby() {
|
|
|
|
static async createLobby() {
|
|
|
|
if (await submitUsername()) {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
mutation {
|
|
|
|
mutation {
|
|
|
|
bingo {
|
|
|
|
bingo {
|
|
|
@ -139,13 +59,12 @@ async function createLobby() {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Lets the player leave the lobby
|
|
|
|
* Leaves a lobby via the graphql endpoint
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function leaveLobby() {
|
|
|
|
static async leaveLobby() {
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
mutation($lobbyId:ID!){
|
|
|
|
mutation($lobbyId:ID!){
|
|
|
|
bingo {
|
|
|
|
bingo {
|
|
|
@ -164,11 +83,11 @@ async function leaveLobby() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Kicks a player by id.
|
|
|
|
* Kicks a player
|
|
|
|
* @param pid
|
|
|
|
* @param pid
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function kickPlayer(pid) {
|
|
|
|
static async kickPlayer(pid) {
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
mutation ($lobbyId: ID!, $playerId:ID!) {
|
|
|
|
mutation ($lobbyId: ID!, $playerId:ID!) {
|
|
|
|
bingo {
|
|
|
|
bingo {
|
|
|
@ -189,6 +108,199 @@ async function kickPlayer(pid) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Loads information about the rounds winner and the round stats.
|
|
|
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static async loadWinnerInfo() {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query($lobbyId:ID!) {
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
currentRound {
|
|
|
|
|
|
|
|
status
|
|
|
|
|
|
|
|
winner {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
username
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
start
|
|
|
|
|
|
|
|
finish
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let roundInfo = response.data.bingo.lobby.currentRound;
|
|
|
|
|
|
|
|
if (roundInfo.winner)
|
|
|
|
|
|
|
|
displayWinner(roundInfo);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
showError('Failed to get round information');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Loads the lobby wors in the words element via graphql.
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static async loadLobbyWords() {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query($lobbyId:ID!){
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
words {
|
|
|
|
|
|
|
|
content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let wordContainer = document.querySelector('#bingo-words');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wordContainer)
|
|
|
|
|
|
|
|
wordContainer.innerHTML = `<span class="bingoWord">
|
|
|
|
|
|
|
|
${response.data.bingo.lobby.words.map(x => x.content).join('</span><span class="bingoWord">')}</span>`;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('Failed to load words.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets the settings of the lobby
|
|
|
|
|
|
|
|
* @param words
|
|
|
|
|
|
|
|
* @param gridSize
|
|
|
|
|
|
|
|
* @returns {Promise<LobbyWrapper.words|*|properties.words|{default, type}|boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static async setLobbySettings(words, gridSize) {
|
|
|
|
|
|
|
|
gridSize = Number(gridSize);
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
mutation ($lobbyId: ID!, $words: [String!]!, $gridSize:Int!) {
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
mutateLobby(id: $lobbyId) {
|
|
|
|
|
|
|
|
setWords(words: $words) {
|
|
|
|
|
|
|
|
words {
|
|
|
|
|
|
|
|
content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setGridSize(gridSize: $gridSize) {
|
|
|
|
|
|
|
|
gridSize
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`, {lobbyId: getLobbyParam(), words: words, gridSize: gridSize});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
return response.data.bingo.mutateLobby.setWords.words;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
if (response.errors)
|
|
|
|
|
|
|
|
showError(response.errors[0].message);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
showError('Error when submitting lobby settings.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the value of the url-param 'g'
|
|
|
|
|
|
|
|
* @returns {string}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getLobbyParam() {
|
|
|
|
|
|
|
|
let matches = window.location.href.match(/\??&?g=(\d+)/);
|
|
|
|
|
|
|
|
if (matches)
|
|
|
|
|
|
|
|
return matches[1];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Spawns a notification when the window is inactive (hidden).
|
|
|
|
|
|
|
|
* @param body
|
|
|
|
|
|
|
|
* @param title
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function spawnNotification(body, title) {
|
|
|
|
|
|
|
|
if (Notification.permission !== 'denied' && document[getHiddenNames().hidden]) {
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
|
|
|
body: body,
|
|
|
|
|
|
|
|
icon: '/favicon.ico'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let n = new Notification(title, options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Submits the value of the username-input to set the username.
|
|
|
|
|
|
|
|
* @returns {Promise<Boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function submitUsername() {
|
|
|
|
|
|
|
|
let unameInput = document.querySelector('#input-username');
|
|
|
|
|
|
|
|
let username = unameInput.value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (username.length > 1 && username.length <= 30) {
|
|
|
|
|
|
|
|
return await BingoGraphqlHelper.setUsername(username);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('You need to provide a username (min. 2 characters, max. 30)!');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Function that displays the ping in the console.
|
|
|
|
|
|
|
|
* @returns {Promise<number>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function ping() {
|
|
|
|
|
|
|
|
let start = new Date().getTime();
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query {
|
|
|
|
|
|
|
|
time
|
|
|
|
|
|
|
|
}`);
|
|
|
|
|
|
|
|
console.log(`Ping: ${(new Date().getTime()) - start} ms`);
|
|
|
|
|
|
|
|
return (new Date().getTime()) - start;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Joins a lobby or says to create one if none is found
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function joinLobby() {
|
|
|
|
|
|
|
|
if (getLobbyParam()) {
|
|
|
|
|
|
|
|
if (await submitUsername())
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('No lobby found. Please create one.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Creates a lobby and redirects to the lobby.
|
|
|
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function createLobby() {
|
|
|
|
|
|
|
|
if (await submitUsername())
|
|
|
|
|
|
|
|
await BingoGraphqlHelper.createLobby();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Lets the player leave the lobby
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function leaveLobby() {
|
|
|
|
|
|
|
|
await BingoGraphqlHelper.leaveLobby();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Kicks a player by id.
|
|
|
|
|
|
|
|
* @param pid
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function kickPlayer(pid) {
|
|
|
|
|
|
|
|
await BingoGraphqlHelper.kickPlayer(pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Executes a command
|
|
|
|
* Executes a command
|
|
|
|
* @param message {String} - the message
|
|
|
|
* @param message {String} - the message
|
|
|
@ -197,6 +309,7 @@ async function executeCommand(message) {
|
|
|
|
function reply(content) {
|
|
|
|
function reply(content) {
|
|
|
|
addChatMessage({content: content, htmlContent: content, type: 'INFO'});
|
|
|
|
addChatMessage({content: content, htmlContent: content, type: 'INFO'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let jsStyle = document.querySelector('#js-style');
|
|
|
|
let jsStyle = document.querySelector('#js-style');
|
|
|
|
message = message.replace(/\s+$/g, '');
|
|
|
|
message = message.replace(/\s+$/g, '');
|
|
|
|
let command = /(\/\w+) ?(.*)?/g.exec(message);
|
|
|
|
let command = /(\/\w+) ?(.*)?/g.exec(message);
|
|
|
@ -228,7 +341,7 @@ async function executeCommand(message) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case '/username':
|
|
|
|
case '/username':
|
|
|
|
if (command[2]) {
|
|
|
|
if (command[2]) {
|
|
|
|
let uname = await setUsername(command[2]);
|
|
|
|
let uname = await BingoGraphqlHelper.setUsername(command[2]);
|
|
|
|
reply(`Your username is <b>${uname}</b> now.`);
|
|
|
|
reply(`Your username is <b>${uname}</b> now.`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
reply('You need to provide a username');
|
|
|
|
reply('You need to provide a username');
|
|
|
@ -252,67 +365,11 @@ async function sendChatMessage() {
|
|
|
|
if (messageInput.value && messageInput.value.length > 0) {
|
|
|
|
if (messageInput.value && messageInput.value.length > 0) {
|
|
|
|
let message = messageInput.value;
|
|
|
|
let message = messageInput.value;
|
|
|
|
messageInput.value = '';
|
|
|
|
messageInput.value = '';
|
|
|
|
if (/^\/\.*/g.test(message)) {
|
|
|
|
|
|
|
|
await executeCommand(message);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
mutation($lobbyId:ID!, $message:String!){
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
mutateLobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
sendMessage(message:$message) {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
htmlContent
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
author {
|
|
|
|
|
|
|
|
username
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {message: message, lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
addChatMessage(response.data.bingo.mutateLobby.sendMessage);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
messageInput.value = message;
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
showError('Error when sending message.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
if (/^\/\.*/g.test(message))
|
|
|
|
* Sets the words for the lobby
|
|
|
|
await executeCommand(message);
|
|
|
|
* @param words
|
|
|
|
|
|
|
|
* @param gridSize
|
|
|
|
|
|
|
|
* @returns {Promise<LobbyWrapper.words|*|properties.words|{default, type}|boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function setLobbySettings(words, gridSize) {
|
|
|
|
|
|
|
|
gridSize = Number(gridSize);
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
mutation ($lobbyId: ID!, $words: [String!]!, $gridSize:Int!) {
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
mutateLobby(id: $lobbyId) {
|
|
|
|
|
|
|
|
setWords(words: $words) {
|
|
|
|
|
|
|
|
words {
|
|
|
|
|
|
|
|
content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setGridSize(gridSize: $gridSize) {
|
|
|
|
|
|
|
|
gridSize
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`, {lobbyId: getLobbyParam(), words: words, gridSize: gridSize});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
return response.data.bingo.mutateLobby.setWords.words;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
if (response.errors)
|
|
|
|
|
|
|
|
showError(response.errors[0].message);
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
showError('Error when submitting lobby settings.');
|
|
|
|
socket.emit('message', message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -325,7 +382,7 @@ async function startRound() {
|
|
|
|
let words = getLobbyWords();
|
|
|
|
let words = getLobbyWords();
|
|
|
|
if (words.length > 0) {
|
|
|
|
if (words.length > 0) {
|
|
|
|
let gridSize = document.querySelector('#input-grid-size').value || 3;
|
|
|
|
let gridSize = document.querySelector('#input-grid-size').value || 3;
|
|
|
|
let resultWords = await setLobbySettings(words, gridSize);
|
|
|
|
let resultWords = await BingoGraphqlHelper.setLobbySettings(words, gridSize);
|
|
|
|
if (resultWords) {
|
|
|
|
if (resultWords) {
|
|
|
|
textinput.value = resultWords.map(x => x.content).join('\n');
|
|
|
|
textinput.value = resultWords.map(x => x.content).join('\n');
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
@ -393,6 +450,7 @@ async function submitFieldToggle(wordPanel) {
|
|
|
|
document.querySelector('#container-bingo-button').setAttribute('class', '');
|
|
|
|
document.querySelector('#container-bingo-button').setAttribute('class', '');
|
|
|
|
else
|
|
|
|
else
|
|
|
|
document.querySelector('#container-bingo-button').setAttribute('class', 'hidden');
|
|
|
|
document.querySelector('#container-bingo-button').setAttribute('class', 'hidden');
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.error(response);
|
|
|
|
console.error(response);
|
|
|
|
showError('Error when submitting field toggle');
|
|
|
|
showError('Error when submitting field toggle');
|
|
|
@ -506,43 +564,11 @@ async function statusWrap(func) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Loads information about the rounds winner and the round stats.
|
|
|
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function loadWinnerInfo() {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query($lobbyId:ID!) {
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
currentRound {
|
|
|
|
|
|
|
|
status
|
|
|
|
|
|
|
|
winner {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
username
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
start
|
|
|
|
|
|
|
|
finish
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let roundInfo = response.data.bingo.lobby.currentRound;
|
|
|
|
|
|
|
|
if (roundInfo.winner)
|
|
|
|
|
|
|
|
displayWinner(roundInfo);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
showError('Failed to get round information');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Adds a message to the chat
|
|
|
|
* Adds a message to the chat
|
|
|
|
* @param messageObject {Object} - the message object returned by graphql
|
|
|
|
* @param messageObject {Object} - the message object returned by graphql
|
|
|
|
* @param player {Number} - the id of the player
|
|
|
|
* @param [player] {Number} - the id of the player
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function addChatMessage(messageObject, player) {
|
|
|
|
function addChatMessage(messageObject, player) {
|
|
|
|
let msgSpan = document.createElement('span');
|
|
|
|
let msgSpan = document.createElement('span');
|
|
|
@ -558,8 +584,10 @@ function addChatMessage(messageObject, player) {
|
|
|
|
msgSpan.innerHTML = `
|
|
|
|
msgSpan.innerHTML = `
|
|
|
|
<span class="chatMessageContent ${messageObject.type}">${messageObject.htmlContent}</span>`;
|
|
|
|
<span class="chatMessageContent ${messageObject.type}">${messageObject.htmlContent}</span>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (messageObject.author && messageObject.author.id !== player)
|
|
|
|
if (messageObject.author && messageObject.author.id !== player)
|
|
|
|
spawnNotification(messageObject.content, messageObject.author.username);
|
|
|
|
spawnNotification(messageObject.content, messageObject.author.username);
|
|
|
|
|
|
|
|
|
|
|
|
let chatContent = document.querySelector('#chat-content');
|
|
|
|
let chatContent = document.querySelector('#chat-content');
|
|
|
|
chatContent.appendChild(msgSpan);
|
|
|
|
chatContent.appendChild(msgSpan);
|
|
|
|
chatContent.scrollTop = chatContent.scrollHeight; // auto-scroll to bottom
|
|
|
|
chatContent.scrollTop = chatContent.scrollHeight; // auto-scroll to bottom
|
|
|
@ -577,231 +605,121 @@ function addPlayer(player, options) {
|
|
|
|
|
|
|
|
|
|
|
|
if (options.isAdmin && player.id !== options.admin)
|
|
|
|
if (options.isAdmin && player.id !== options.admin)
|
|
|
|
playerContainer.innerHTML = `<button class="kickPlayerButton" onclick="kickPlayer(${player.id})">⨯</button>`;
|
|
|
|
playerContainer.innerHTML = `<button class="kickPlayerButton" onclick="kickPlayer(${player.id})">⨯</button>`;
|
|
|
|
|
|
|
|
|
|
|
|
playerContainer.innerHTML += `<span class="playernameSpan">${player.username}</span>`;
|
|
|
|
playerContainer.innerHTML += `<span class="playernameSpan">${player.username}</span>`;
|
|
|
|
|
|
|
|
|
|
|
|
if (player.id === options.admin)
|
|
|
|
if (player.id === options.admin)
|
|
|
|
playerContainer.innerHTML += "<span class='adminSpan'> 👑</span>";
|
|
|
|
playerContainer.innerHTML += "<span class='adminSpan'> 👑</span>";
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelector('#player-list').appendChild(playerContainer);
|
|
|
|
document.querySelector('#player-list').appendChild(playerContainer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Refreshes the bingo chat
|
|
|
|
* Returns the current player id
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function refreshChat() {
|
|
|
|
async function getPlayerInfo() {
|
|
|
|
try {
|
|
|
|
let result = await postGraphqlQuery(`
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query ($lobbyId:ID!) {
|
|
|
|
query ($lobbyId:ID!) {
|
|
|
|
bingo {
|
|
|
|
bingo {
|
|
|
|
player {
|
|
|
|
player {
|
|
|
|
id
|
|
|
|
id
|
|
|
|
}
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
messages {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
htmlContent
|
|
|
|
|
|
|
|
content
|
|
|
|
|
|
|
|
author {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
username
|
|
|
|
username
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let messages = response.data.bingo.lobby.messages;
|
|
|
|
|
|
|
|
for (let message of messages)
|
|
|
|
|
|
|
|
if (!document.querySelector(`.chatMessage[msg-id="${message.id}"]`))
|
|
|
|
|
|
|
|
addChatMessage(message, response.data.bingo.player.id);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('Failed to refresh messages');
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
showError('Failed to refresh messages');
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Refreshes the player list
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function refreshPlayers() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query ($lobbyId: ID!) {
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
player {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
players {
|
|
|
|
|
|
|
|
id
|
|
|
|
id
|
|
|
|
username
|
|
|
|
|
|
|
|
wins(lobbyId: $lobbyId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
admin {
|
|
|
|
admin {
|
|
|
|
id
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
`, {lobbyId: getLobbyParam()});
|
|
|
|
if (result.status === 200) {
|
|
|
|
if (response.status === 200) {
|
|
|
|
let bingoData = result.data.bingo;
|
|
|
|
let players = response.data.bingo.lobby.players;
|
|
|
|
return {
|
|
|
|
let adminId = response.data.bingo.lobby.admin.id;
|
|
|
|
id: bingoData.player.id,
|
|
|
|
let isAdmin = response.data.bingo.player.id === adminId;
|
|
|
|
username: bingoData.player.username,
|
|
|
|
for (let player of players)
|
|
|
|
isAdmin: bingoData.lobby.admin.id === bingoData.player.id
|
|
|
|
if (!document.querySelector(`.playerEntryContainer[b-pid="${player.id}"]`))
|
|
|
|
};
|
|
|
|
addPlayer(player, {admin: adminId, isAdmin: isAdmin});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
showError('Failed to refresh players');
|
|
|
|
showError('Failed to fetch player Id');
|
|
|
|
console.error(response);
|
|
|
|
console.error(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
showError('Failed to refresh players');
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Removes players that are not existent in the player array
|
|
|
|
* Initializes all socket events
|
|
|
|
* @param players {Array<Object>} - player id response of graphql
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function removeLeftPlayers(players) {
|
|
|
|
function initSocketEvents(data) {
|
|
|
|
for (let playerEntry of document.querySelectorAll('.playerEntryContainer'))
|
|
|
|
let playerId = data.id;
|
|
|
|
if (!players.find(x => (x.id === playerEntry.getAttribute('b-pid'))))
|
|
|
|
let indicator = document.querySelector('#status-indicator');
|
|
|
|
playerEntry.remove();
|
|
|
|
indicator.setAttribute('status', 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
socket.on('connect', () => {
|
|
|
|
* Refreshes if a player-refresh is needed.
|
|
|
|
indicator.setAttribute('socket-status', 'connected');
|
|
|
|
* Removes players that are not in the lobby anyomre.
|
|
|
|
});
|
|
|
|
* @param players
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function checkPlayerRefresh(players) {
|
|
|
|
|
|
|
|
let playerRefresh = false;
|
|
|
|
|
|
|
|
removeLeftPlayers(players);
|
|
|
|
|
|
|
|
for (let player of players)
|
|
|
|
|
|
|
|
if (!document.querySelector(`.playerEntryContainer[b-pid="${player.id}"]`))
|
|
|
|
|
|
|
|
playerRefresh = true;
|
|
|
|
|
|
|
|
if (playerRefresh)
|
|
|
|
|
|
|
|
statusWrap(refreshPlayers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
socket.on('reconnect', () => {
|
|
|
|
* Checks if messages need to be refreshed and does it if it needs to.
|
|
|
|
indicator.setAttribute('socket-status', 'connected');
|
|
|
|
* @param messages
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
function checkMessageRefresh(messages) {
|
|
|
|
|
|
|
|
let messageRefresh = false;
|
|
|
|
|
|
|
|
for (let message of messages)
|
|
|
|
|
|
|
|
if (!document.querySelector(`.chatMessage[msg-id="${message.id}"]`))
|
|
|
|
|
|
|
|
messageRefresh = true;
|
|
|
|
|
|
|
|
if (messageRefresh)
|
|
|
|
|
|
|
|
statusWrap(refreshChat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
socket.on('disconnect', () => {
|
|
|
|
* refreshes the lobby and calls itself with a timeout
|
|
|
|
indicator.setAttribute('socket-status', 'disconnected');
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
showError('Disconnected from socket!');
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
async function refreshLobby() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
|
|
|
|
query($lobbyId:ID!){
|
|
|
|
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
players {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
messages {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentRound {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
status
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
words {
|
|
|
|
|
|
|
|
content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let {players, messages, currentRound} = response.data.bingo.lobby;
|
|
|
|
|
|
|
|
checkPlayerRefresh(players);
|
|
|
|
|
|
|
|
checkMessageRefresh(messages);
|
|
|
|
|
|
|
|
let wordContainer = document.querySelector('#bingo-words');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wordContainer)
|
|
|
|
socket.on('reconnecting', () => {
|
|
|
|
wordContainer.innerHTML = `<span class="bingoWord">
|
|
|
|
indicator.setAttribute('socket-status', 'reconnecting');
|
|
|
|
${response.data.bingo.lobby.words.map(x => x.content).join('</span><span class="bingoWord">')}</span>`;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (currentRound && currentRound.status === 'ACTIVE' && Number(currentRound.id) !== Number(getRoundParam())) {
|
|
|
|
socket.on('error', (error) => {
|
|
|
|
insertParam('r', currentRound.id);
|
|
|
|
showError(`Socket Error: ${JSON.stringify(error)}`);
|
|
|
|
spawnNotification('The round started!', 'Bingo');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
socket.on('message', (msg) => {
|
|
|
|
showError('Failed to refresh lobby');
|
|
|
|
console.log(msg);
|
|
|
|
console.error(response);
|
|
|
|
addChatMessage(msg, playerId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('statusChange', (status) => {
|
|
|
|
|
|
|
|
console.log(`Status changed to ${status}`);
|
|
|
|
|
|
|
|
if (status === 'FINISHED')
|
|
|
|
|
|
|
|
BingoGraphqlHelper.loadWinnerInfo();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('playerJoin', (playerObject) => {
|
|
|
|
|
|
|
|
addPlayer(playerObject, data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('playerLeave', (playerId) => {
|
|
|
|
|
|
|
|
document.querySelector(`.playerEntryContainer[b-pid='${playerId}']`).remove();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('usernameChange', (playerObject) => {
|
|
|
|
|
|
|
|
console.log(playerObject);
|
|
|
|
|
|
|
|
document.querySelector(`.playerEntryContainer[b-pid='${playerObject.id}'] .playerNameSpan`).innerText = playerObject.username;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('wordsChange', async () => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await BingoGraphqlHelper.loadLobbyWords();
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
showError('Failed to refresh lobby');
|
|
|
|
showError('Failed to load new lobby words.');
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
setTimeout(refreshLobby, 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Checks the status of the lobby and the current round.
|
|
|
|
* Initializes the lobby refresh with sockets or graphql
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function refreshRound() {
|
|
|
|
function initRefresh() {
|
|
|
|
let roundOver = false;
|
|
|
|
getPlayerInfo().then((data) => {
|
|
|
|
try {
|
|
|
|
socket = new SimpleSocket(`/bingo/${getLobbyParam()}`, {playerId: data.id});
|
|
|
|
let response = await postGraphqlQuery(`
|
|
|
|
initSocketEvents(data);
|
|
|
|
query($lobbyId:ID!) {
|
|
|
|
});
|
|
|
|
bingo {
|
|
|
|
|
|
|
|
lobby(id:$lobbyId) {
|
|
|
|
|
|
|
|
players {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
messages {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentRound {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
status
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, {lobbyId: getLobbyParam()});
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
|
|
let {players, messages, currentRound} = response.data.bingo.lobby;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkPlayerRefresh(players);
|
|
|
|
|
|
|
|
checkMessageRefresh(messages);
|
|
|
|
|
|
|
|
if (!currentRound || currentRound.status === "FINISHED") {
|
|
|
|
|
|
|
|
roundOver = true;
|
|
|
|
|
|
|
|
await loadWinnerInfo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showError('Failed to refresh round');
|
|
|
|
|
|
|
|
console.error(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
showError('Failed to refresh round');
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (!roundOver)
|
|
|
|
|
|
|
|
setTimeout(refreshRound, 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("unhandledrejection", function (promiseRejectionEvent) {
|
|
|
|
window.addEventListener("unhandledrejection", function (promiseRejectionEvent) {
|
|
|
@ -815,7 +733,7 @@ window.addEventListener("keydown", async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
if (document.querySelector('#input-bingo-words')) {
|
|
|
|
if (document.querySelector('#input-bingo-words')) {
|
|
|
|
let gridSize = document.querySelector('#input-grid-size').value || 3;
|
|
|
|
let gridSize = document.querySelector('#input-grid-size').value || 3;
|
|
|
|
await statusWrap(async () => await setLobbySettings(getLobbyWords(), gridSize));
|
|
|
|
await statusWrap(async () => await BingoGraphqlHelper.setLobbySettings(getLobbyWords(), gridSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}, false);
|
|
|
@ -830,3 +748,5 @@ window.onload = async () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let socket = null;
|
|
|
|