tournament: add: player can join tournament now
This commit is contained in:
@ -20,6 +20,8 @@ class Tourmanent
|
||||
this.levels = levels;
|
||||
this.state = this.get_state();
|
||||
this.id = id
|
||||
|
||||
this.connected = false;
|
||||
}
|
||||
|
||||
get_state()
|
||||
@ -50,6 +52,48 @@ class Tourmanent
|
||||
this.levels = response_data.levels;
|
||||
this.id = response_data.id
|
||||
}
|
||||
|
||||
leave(event)
|
||||
{
|
||||
if (this.connected == false)
|
||||
return
|
||||
this.connected = false;
|
||||
this._socket.close()
|
||||
this.disconnect_func(event);
|
||||
}
|
||||
|
||||
toggle_participation()
|
||||
{
|
||||
if (!this.connected)
|
||||
return
|
||||
console.log(this.isParticipating);
|
||||
this.isParticipating = !this.isParticipating;
|
||||
console.log(this.isParticipating);
|
||||
this._socket.send(JSON.stringify({participate: this.isParticipating}));
|
||||
}
|
||||
|
||||
async join(receive_func, disconnect_func)
|
||||
{
|
||||
if (!await this.client.isAuthentificate())
|
||||
return null;
|
||||
|
||||
let url = `wss://${window.location.host}/ws/tournaments/${this.id}`;
|
||||
|
||||
this._socket = new WebSocket(url);
|
||||
|
||||
this.connected = true;
|
||||
this.isParticipating = false;
|
||||
|
||||
this.receive_func = receive_func;
|
||||
this.disconnect_func = disconnect_func;
|
||||
|
||||
this._socket.onmessage = function (event) {
|
||||
const data = JSON.parse(event.data);
|
||||
receive_func(data);
|
||||
};
|
||||
|
||||
this._socket.onclose = this.leave.bind(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user