-
Notifications
You must be signed in to change notification settings - Fork 2
/
room-options.ts
129 lines (113 loc) · 3.59 KB
/
room-options.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import * as Ably from 'ably';
/**
* Represents the default options for a chat room.
*/
export const RoomOptionsDefaults = {
/**
* The default presence options for a chat room.
*/
presence: {
/**
* The client should be able to enter presence.
*/
enter: true,
/**
* The client should be able to subscribe to presence.
*/
subscribe: true,
} as PresenceOptions,
/**
* The default typing options for a chat room.
*/
typing: {
/**
* The default timeout for typing events in milliseconds.
*/
timeoutMs: 5000,
} as TypingOptions,
/**
* The default reactions options for a chat room.
*/
reactions: {} as RoomReactionsOptions,
/**
* The default occupancy options for a chat room.
*/
occupancy: {} as OccupancyOptions,
};
/**
* Represents the presence options for a chat room.
*/
export interface PresenceOptions {
/**
* Whether the underlying Realtime channel should use the presence enter mode, allowing entry into presence.
* This property does not affect the presence lifecycle, and users must still call {@link Presence.enter}
* in order to enter presence.
* @defaultValue true
*/
enter?: boolean;
/**
* Whether the underlying Realtime channel should use the presence subscribe mode, allowing subscription to presence.
* This property does not affect the presence lifecycle, and users must still call {@link Presence.subscribe}
* in order to subscribe to presence.
* @defaultValue true
*/
subscribe?: boolean;
}
/**
* Represents the typing options for a chat room.
*/
export interface TypingOptions {
/**
* The timeout for typing events in milliseconds. If typing.start() is not called for this amount of time, a stop
* typing event will be fired, resulting in the user being removed from the currently typing set.
* @defaultValue 5000
*/
timeoutMs: number;
}
/**
* Represents the reactions options for a chat room.
*/
export type RoomReactionsOptions = object;
/**
* Represents the occupancy options for a chat room.
*/
export type OccupancyOptions = object;
/**
* Represents the options for a given chat room.
*/
export interface RoomOptions {
/**
* The presence options for the room. To enable presence in the room, set this property. You may
* use {@link RoomOptionsDefaults.presence} to enable presence with default options.
* @defaultValue undefined
*/
presence?: PresenceOptions;
/**
* The typing options for the room. To enable typing in the room, set this property. You may use
* {@link RoomOptionsDefaults.typing} to enable typing with default options.
*/
typing?: TypingOptions;
/**
* The reactions options for the room. To enable reactions in the room, set this property. You may use
* {@link RoomOptionsDefaults.reactions} to enable reactions with default options.
*/
reactions?: RoomReactionsOptions;
/**
* The occupancy options for the room. To enable occupancy in the room, set this property. You may use
* {@link RoomOptionsDefaults.occupancy} to enable occupancy with default options.
*/
occupancy?: OccupancyOptions;
}
/**
* Creates an {@link ErrorInfo} for invalid room configuration.
*
* @param reason The reason for the invalid room configuration.
* @returns An ErrorInfo.
*/
const invalidRoomConfiguration = (reason: string): Error =>
new Ably.ErrorInfo(`invalid room configuration: ${reason}`, 40001, 400);
export const validateRoomOptions = (options: RoomOptions): void => {
if (options.typing && options.typing.timeoutMs <= 0) {
throw invalidRoomConfiguration('typing timeout must be greater than 0');
}
};