blob: 77d667671a161265821f1c51c38680148017e9e3 (
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
41
42
43
44
45
|
import type AkkamonSession from './session';
import type { GameState } from './GameState';
import { Socket } from './socket';
import {
EventType,
HeartBeatReplyEvent,
AkkamonEvent
} from './events';
export class Client
{
private session: AkkamonSession;
private akkamonState?: GameState;
constructor(
url: string
) {
this.session = new Socket(url, this);
}
getMutableState(): GameState {
return this.akkamonState!;
}
in(eventString: string) {
let event: AkkamonEvent = JSON.parse(eventString);
console.log("-> client is handling incoming event:");
console.log(event);
switch (event.type) {
case EventType.HEART_BEAT:
this.send(new HeartBeatReplyEvent());
break;
}
}
send(event: AkkamonEvent) {
// console.log("-> client is now sending out message:");
// console.log(event)
if (this.session) {
this.session.send(JSON.stringify(event));
}
}
}
|