42 lines
678 B
JavaScript
42 lines
678 B
JavaScript
|
import { client, navigateTo } from "../index.js"
|
||
|
|
||
|
class MatchMaking
|
||
|
{
|
||
|
/**
|
||
|
* @param {client} client
|
||
|
*/
|
||
|
constructor(client)
|
||
|
{
|
||
|
/**
|
||
|
* @type {client}
|
||
|
*/
|
||
|
this.client = client
|
||
|
}
|
||
|
|
||
|
async start(func)
|
||
|
{
|
||
|
if (!await this.client.isAuthentificate())
|
||
|
return null;
|
||
|
|
||
|
console.log(func)
|
||
|
this.callback = func
|
||
|
console.log(this.callback)
|
||
|
|
||
|
let url = `wss://${window.location.host}/ws/matchmaking/`;
|
||
|
|
||
|
this._chatSocket = new WebSocket(url);
|
||
|
|
||
|
this._chatSocket.onmessage = function (event) {
|
||
|
const data = JSON.parse(event.data);
|
||
|
console.log(func, data)
|
||
|
func(data.game_id)
|
||
|
};
|
||
|
}
|
||
|
|
||
|
async stop()
|
||
|
{
|
||
|
this._chatSocket.close()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export {MatchMaking}
|