fix: matchmaking support start stop, multi connection

This commit is contained in:
2023-12-23 16:47:22 +01:00
parent 6c39a13aca
commit c02c49215d
5 changed files with 92 additions and 32 deletions

View File

@ -14,7 +14,7 @@ class MatchMaking
this.searching = false;
}
async start(func, mode)
async start(receive_func, disconnect_func, mode)
{
if (!await this.client.isAuthentificate())
return null;
@ -25,10 +25,21 @@ class MatchMaking
this.searching = true;
this.receive_func = receive_func;
this.disconnect_func = disconnect_func;
this._socket.onmessage = function (event) {
const data = JSON.parse(event.data);
func(data.game_id)
receive_func(data);
};
this._socket.onclose = this.onclose.bind(this);
}
onclose(event)
{
this.stop();
this.disconnect_func()
}
async stop()