ft_transcendence/frontend/static/js/api/matchmaking.js

37 lines
567 B
JavaScript
Raw Normal View History

2023-12-16 12:00:38 -05:00
import { Client } from "./client.js";
2023-12-12 06:06:13 -05:00
class MatchMaking
{
/**
2023-12-16 12:00:38 -05:00
* @param {Client} client
2023-12-12 06:06:13 -05:00
*/
constructor(client)
{
/**
* @type {client}
*/
this.client = client
}
async start(func)
{
if (!await this.client.isAuthentificate())
return null;
let url = `wss://${window.location.host}/ws/matchmaking/`;
this._chatSocket = new WebSocket(url);
this._chatSocket.onmessage = function (event) {
const data = JSON.parse(event.data);
func(data.game_id)
};
}
async stop()
{
this._chatSocket.close()
}
}
export {MatchMaking}