-
Notifications
You must be signed in to change notification settings - Fork 1
/
messages.ts
69 lines (57 loc) · 1.56 KB
/
messages.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
export type MessageType =
| "StateUpdate"
| "CallFunction"
| "SubscribeState"
| "SubscribeFunction"
| "UnsubscribeState"
| "UnsubscribeFunction"
| "RoommateSubscribed"
| "RoommateUnsubscribed"
export interface Message {
/**
* A distinct ID generated by the client for deduplication
*/
MessageID: string
MessageType: MessageType
/**
* NOT IMPLEMENTED - Added by the server (so all clients have a timestamp to "agree" on.
* This means that a client with a wonky clock will only impact itself,
* not all other clients!
*/
MessageMS: number
/**
* Added by the server, ID of the invoking client (undefined if sent by server)
*/
ClientID?: string
RoomID: string
/**
* If a `MessageType = 'StateUpdate'`, represents a serizable JSON value
*/
Value?: any
/**
* If a `MessageType = 'CallFunction', the parameters of the called function
*/
Args?: any[]
}
export interface SubscribeMessage extends Message {
MessageType: "SubscribeState" | "SubscribeFunction"
}
export interface UnsubscribeMessage extends Message {
MessageType: "UnsubscribeState" | "UnsubscribeFunction"
}
export interface StateUpdateMessage extends Message {
MessageType: "StateUpdate"
Value: string
}
export interface CallFunctionMessage extends Message {
MessageType: "CallFunction"
Args: any[]
}
export interface RoommateSubscribedMessage extends Message {
MessageType: "RoommateSubscribed"
ClientID: string
}
export interface RoommateUnsubscribedMessage extends Message {
MessageType: "RoommateUnsubscribed"
ClientID: string
}