Added disconnect method on return, removed promise from close
This commit is contained in:
parent
033bbbea03
commit
9df04610ef
@ -64,8 +64,8 @@ export default class WebSocketService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async close(): Promise<void> {
|
public close(): void {
|
||||||
return new Promise(() => this.ws?.close());
|
this.ws?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public isOpen(): boolean {
|
public isOpen(): boolean {
|
||||||
|
@ -31,6 +31,7 @@ export const GameComponent: Component = () => {
|
|||||||
|
|
||||||
game.connectToServer();
|
game.connectToServer();
|
||||||
startGameLoop();
|
startGameLoop();
|
||||||
|
return () => game.disconnect();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -3,7 +3,7 @@ import {Action} from "../classes/actions";
|
|||||||
|
|
||||||
export default class Game {
|
export default class Game {
|
||||||
|
|
||||||
private _wsService: WebSocketService;
|
private readonly _wsService: WebSocketService;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._wsService = new WebSocketService("wss://localhost:3000/api/game");
|
this._wsService = new WebSocketService("wss://localhost:3000/api/game");
|
||||||
@ -38,6 +38,10 @@ export default class Game {
|
|||||||
public isConnected(): boolean {
|
public isConnected(): boolean {
|
||||||
return this._wsService.isOpen();
|
return this._wsService.isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public disconnect(): void {
|
||||||
|
this._wsService.close();
|
||||||
|
}
|
||||||
|
|
||||||
private createPlayers(): void {
|
private createPlayers(): void {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user