[HQ] Return console.logs instead of errors if ws is closed
This commit is contained in:
@@ -100,12 +100,13 @@ export default class Client {
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log('No WebSocket connection is active.');
|
||||
this.ws.send(JSON.stringify({
|
||||
type: 'subscribe',
|
||||
broadcastId: this.broadcastID,
|
||||
}));
|
||||
if (this.logging) console.log(`${` Client ${this.index} `.bgBlue.black}${' Subscribed '.bgGreen.black}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
parse(msg) {
|
||||
@@ -148,7 +149,8 @@ export default class Client {
|
||||
|
||||
submitAnswer(index) {
|
||||
if (!this.inTheGame) return;
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
// eslint-disable-next-line consistent-return
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log(`Client ${this.index} | No WebSocket connection is active.`);
|
||||
if (index > 2 || index < 0) {
|
||||
if (this.debug) console.log(`${` Client ${this.index} [DEBUG] `.bgBlue.black}${' Invalid index given to submitAnswer. '.bgRed.black}`);
|
||||
return;
|
||||
@@ -165,8 +167,8 @@ export default class Client {
|
||||
}
|
||||
|
||||
useExtraLife() {
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
if (!this.hasExtraLife) return;
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log(`Client ${this.index} | No WebSocket connection is active.`);
|
||||
if (!this.hasExtraLife) return false;
|
||||
this.ws.send(JSON.stringify({
|
||||
type: 'useExtraLife',
|
||||
broadcastId: this.broadcastID,
|
||||
@@ -174,33 +176,37 @@ export default class Client {
|
||||
}));
|
||||
this.inTheGame = true;
|
||||
if (this.logging) console.log(`${` Client ${this.index} `.bgBlue.black}${' Used Extra Life '.bgGreen.black}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
useEraser() {
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
if (!this.hasEraser) return;
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log(`Client ${this.index} | No WebSocket connection is active.`);
|
||||
if (!this.hasEraser) return false;
|
||||
this.socket.send(JSON.stringify({ type: 'erase1', questionId: this.questionID, broadcastId: this.broadcastID }));
|
||||
return true;
|
||||
}
|
||||
|
||||
spinWheel(letter) {
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log(`Client ${this.index} | No WebSocket connection is active.`);
|
||||
this.ws.send(JSON.stringify({
|
||||
showId: this.showID,
|
||||
type: 'spin',
|
||||
nearbyIds: [],
|
||||
letter,
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
guess() {
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) throw new Error('No WebSocket connection is active.');
|
||||
if (!this.inTheGame) return;
|
||||
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return console.log('No WebSocket connection is active.');
|
||||
if (!this.inTheGame) return false;
|
||||
this.ws.send(JSON.stringify({
|
||||
type: 'guess',
|
||||
letter: this.letter,
|
||||
roundId: this.roundID,
|
||||
showId: this.showID,
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
async getBalance() {
|
||||
|
||||
Reference in New Issue
Block a user