Added disconnect method on return, removed promise from close

This commit is contained in:
Martin Berg Alstad 2023-05-19 23:24:46 +02:00
parent 033bbbea03
commit 9df04610ef
3 changed files with 8 additions and 3 deletions

View File

@ -64,8 +64,8 @@ export default class WebSocketService {
});
}
public async close(): Promise<void> {
return new Promise(() => this.ws?.close());
public close(): void {
this.ws?.close();
}
public isOpen(): boolean {

View File

@ -31,6 +31,7 @@ export const GameComponent: Component = () => {
game.connectToServer();
startGameLoop();
return () => game.disconnect();
}, []);
return (

View File

@ -3,7 +3,7 @@ import {Action} from "../classes/actions";
export default class Game {
private _wsService: WebSocketService;
private readonly _wsService: WebSocketService;
constructor() {
this._wsService = new WebSocketService("wss://localhost:3000/api/game");
@ -38,6 +38,10 @@ export default class Game {
public isConnected(): boolean {
return this._wsService.isOpen();
}
public disconnect(): void {
this._wsService.close();
}
private createPlayers(): void {
throw new Error("Not implemented");