-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.ts
More file actions
56 lines (48 loc) · 1.41 KB
/
Copy pathprotocol.ts
File metadata and controls
56 lines (48 loc) · 1.41 KB
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
49
50
51
52
53
54
55
56
/**
* Mirror of the backend's WsMessage envelope (see WsMessage.java).
* Every frame on the wire, in either direction, has this shape.
*/
export type Role = 'control' | 'display' | 'observer'
export type MessageType =
| 'JOIN'
| 'WELCOME'
| 'PRESENCE'
| 'EVENT'
| 'BROADCAST'
| 'RENAME'
| 'ERROR'
/** Who a message came from: server-assigned id, current name, declared role. */
export interface Sender {
id: string
name: string
role: Role
}
export const ROLE_ICONS: Record<Role, string> = {
control: '🎛',
display: '📺',
observer: '👁',
}
export interface WsMessage {
type: MessageType
/**
* Stamped by the server on routed messages; null on client-sent messages
* (the server never trusts a client-supplied identity) and on
* server-originated ones (WELCOME, PRESENCE, ERROR).
*/
sender: Sender | null
payload: unknown
/** Epoch millis, stamped by the server. */
timestamp: number
}
/** Payload of a WELCOME message: this client's own identity. */
export type WelcomePayload = Sender
/** Payload of a PRESENCE message: everyone currently connected. */
export interface PresencePayload {
roster: Sender[]
}
/** Application-level events the UIs exchange (the payload of EVENT and BROADCAST). */
export type AppEvent =
| { kind: 'announcement'; text: string }
| { kind: 'set-color'; color: string }
| { kind: 'reaction'; emoji: string }
| { kind: 'ack'; of: string }