summaryrefslogtreecommitdiff
path: root/client/src/socket.ts
blob: 8e2b9ef1cbaf43cf527559c55ff9f4f5104a7a90 (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
import Phaser from 'phaser';
import type { Client } from './client'
import type AkkamonSession from './session'
import {
    PlayerRegistrationEvent
} from './events';

export class Socket extends WebSocket implements AkkamonSession
{
    constructor(
        url: string,
        client: Client
    ) {
        super(url);

        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.send(new PlayerRegistrationEvent());
        }

        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);
        }
    }

}