add: tournament: graph de bz
This commit is contained in:
@ -102,7 +102,7 @@ class Tourmanent
|
||||
return;
|
||||
this.connected = false;
|
||||
this._socket.close();
|
||||
this.disconnect_func(event);
|
||||
this.disconnectHandler(event);
|
||||
}
|
||||
|
||||
toggle_participation()
|
||||
@ -112,13 +112,40 @@ class Tourmanent
|
||||
this._socket.send(JSON.stringify({participate: ""}));
|
||||
}
|
||||
|
||||
async onParticipantsUpdate(data)
|
||||
{
|
||||
oldParticipantList = this.par
|
||||
|
||||
await this.participantsUpdateHandler();
|
||||
}
|
||||
|
||||
async onError(data)
|
||||
{
|
||||
await this.errorHandler(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MessageEvent} event
|
||||
*/
|
||||
onReceive(event)
|
||||
{
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
if (data?.detail === "error")
|
||||
this.onError(data);
|
||||
else if (data?.detail === "participants_update")
|
||||
this.onParticipantsUpdate(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Join the tournament Websocket
|
||||
* @param {CallableFunction} receive_func
|
||||
* @param {CallableFunction} disconnect_func
|
||||
* @param {CallableFunction} errorHandler
|
||||
* @param {CallableFunction} participantsUpdateHandler
|
||||
* @param {CallableFunction} disconnectHandler
|
||||
* @returns {?}
|
||||
*/
|
||||
async join(receive_func, disconnect_func)
|
||||
async join(participantsUpdateHandler, errorHandler, disconnectHandler)
|
||||
{
|
||||
if (!await this.client.isAuthenticated())
|
||||
return null;
|
||||
@ -130,13 +157,11 @@ class Tourmanent
|
||||
this.connected = true;
|
||||
this.isParticipating = false;
|
||||
|
||||
this.receive_func = receive_func;
|
||||
this.disconnect_func = disconnect_func;
|
||||
this.participantsUpdateHandler = participantsUpdateHandler;
|
||||
this.errorHandler = errorHandler;
|
||||
this.disconnectHandler = disconnectHandler;
|
||||
|
||||
this._socket.onmessage = function (event) {
|
||||
const data = JSON.parse(event.data);
|
||||
receive_func(data);
|
||||
};
|
||||
this._socket.onmessage = this.onReceive.bind(this);
|
||||
|
||||
this._socket.onclose = this.leave.bind(this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user