blob: cfd8ce364bf3e01761d39624276d4e553b5f85a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}
}
}
|