From 0f8edbe0b2c0bd09cd40872f06993c08e67f26cb Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Thu, 15 Jul 2021 11:52:28 +0200 Subject: refactor(client/api): need to debug! --- client/src/socket.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 client/src/socket.ts (limited to 'client/src/socket.ts') diff --git a/client/src/socket.ts b/client/src/socket.ts new file mode 100644 index 0000000..cfd8ce3 --- /dev/null +++ b/client/src/socket.ts @@ -0,0 +1,40 @@ +import Phaser from 'phaser'; +import Client from './client' +import type AkkamonSession from './session' + +export default class Socket extends WebSocket implements AkkamonSession +{ + static instance: AkkamonSession; + + static getInstance(url: string, user: {name: string, password: string}) { + if (Socket.instance) return Socket.instance; + else { + Socket.instance = new Socket(url, user); + return Socket.instance; + } + } + + constructor(url: string, user: {name: string, password: string}) { + super(url); + + let client = Client.getInstance(); + + let session = this; + + this.onopen = function echo(this: WebSocket, ev: Event) { + console.log("opening socket"); + console.log("this is the websocket"); + console.log(this); + console.log("logging in the session to the server"); + client.login(user); + } + + this.onmessage = function incomingMessage(this: WebSocket, ev: MessageEvent) { + console.log("received message from the server!"); + console.log("-> " + ev.data); + console.log("calling client.in:"); + client.in(ev.data); + } + } + +} -- cgit v1.2.3