summaryrefslogtreecommitdiff
path: root/client/src/socket.ts
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2021-07-15 11:52:28 +0200
committerMike Vink <mike1994vink@gmail.com>2021-07-15 11:52:28 +0200
commit0f8edbe0b2c0bd09cd40872f06993c08e67f26cb (patch)
tree93a9943eaf7baeb5bdbeb489f867dc1d0bb13cac /client/src/socket.ts
parent9d54842c2f5b084ab1b0de4c4b8978cc43297546 (diff)
refactor(client/api): need to debug!
Diffstat (limited to 'client/src/socket.ts')
-rw-r--r--client/src/socket.ts40
1 files changed, 40 insertions, 0 deletions
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);
+ }
+ }
+
+}