-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet.ts
48 lines (40 loc) · 901 Bytes
/
net.ts
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
46
47
48
//@ts-strict
import { WebSocket } from 'ws'
import { Option } from './structs'
export interface WS extends WebSocket {
user_id?: string
session_id?: string
is_alive?: boolean
}
export enum ServerMsgType {
create = 'create',
join = 'join',
guess = 'guess',
again = 'again',
}
export enum ClientMsgType {
user_id = 'user_id',
session_id = 'session_id',
info = 'info',
again = 'again',
guess = 'guess',
error = 'error',
}
type MsgType = ServerMsgType | ClientMsgType
export const MsgType = { ...ServerMsgType, ...ClientMsgType }
export interface Message {
type: MsgType
user_id?: string
session_id?: string
content?: string | { guess: Option[]; rem: number }
log?: boolean
}
export interface ServerMessage extends Message {
type: ServerMsgType
}
export interface ClientMessage extends Message {
type: ClientMsgType
}
export interface User {
id: string
}