This repository was archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
53 lines (41 loc) · 1.44 KB
/
types.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
export enum RealtimeComponentState {
STARTED = 'STARTED',
STOPPED = 'STOPPED',
}
export enum RealtimeChannelState {
DISCONNECTED = 'DISCONNECTED',
CONNECTED = 'CONNECTED',
CONNECTING = 'CONNECTING',
}
export enum RealtimeComponentEvent {
REALTIME_STATE_CHANGED = 'realtime-component.state-changed',
}
export enum RealtimeChannelEvent {
REALTIME_CHANNEL_STATE_CHANGED = 'realtime-channel.state-changed',
}
export type RealtimeData = {
name: string;
payload: any;
};
export type RealtimeMessage<T = unknown> = {
name: string;
connectionId: string;
participantId: string | null;
data: T;
timestamp: number;
};
type ChannelEvents = RealtimeChannelEvent | `${RealtimeChannelEvent}`;
type ComponentEvents = RealtimeComponentEvent | `${RealtimeComponentEvent}`;
type ChannelState = RealtimeChannelState | `${RealtimeChannelState}`;
type ComponentState = RealtimeComponentState | `${RealtimeComponentState}`;
type States = ChannelState | ComponentState;
export type Callback<T> = (data: T extends States ? T : RealtimeMessage<T>) => void;
export type RealtimeChannelSubscribe = {
<T>(event: ChannelEvents, callback?: Callback<ChannelState>): void;
<T>(event: string, callback?: Callback<T>): void;
};
export type RealtimeComponentSubscribe = {
<T>(event: ComponentEvents, callback?: Callback<ComponentState>): void;
<T>(event: string, callback?: Callback<T>): void;
};
export type RealtimePublish = <T>(event: string, data: T) => void;