add: matchmaking
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { Account } from "./account.js";
|
||||
import { MatchMaking } from "./matchmaking.js";
|
||||
import { Profile } from "./profile.js";
|
||||
import { Profiles } from "./profiles.js";
|
||||
|
||||
@ -19,6 +20,7 @@ class Client
|
||||
this._url = url;
|
||||
this.account = new Account(this);
|
||||
this.profiles = new Profiles(this);
|
||||
this.matchmaking = new MatchMaking(this);
|
||||
this._logged = undefined;
|
||||
}
|
||||
|
||||
|
42
frontend/static/js/api/matchmaking.js
Normal file
42
frontend/static/js/api/matchmaking.js
Normal file
@ -0,0 +1,42 @@
|
||||
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}
|
Reference in New Issue
Block a user