-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoomOptions.kt
98 lines (88 loc) · 2.99 KB
/
RoomOptions.kt
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
package com.ably.chat
/**
* Represents the options for a given chat room.
*/
data class RoomOptions(
/**
* The presence options for the room. To enable presence in the room, set this property. You may
* use [RoomOptionsDefaults.presence] to enable presence with default options.
* @defaultValue undefined
*/
val presence: PresenceOptions? = null,
/**
* The typing options for the room. To enable typing in the room, set this property. You may use
* [RoomOptionsDefaults.typing] to enable typing with default options.
*/
val typing: TypingOptions? = null,
/**
* The reactions options for the room. To enable reactions in the room, set this property. You may use
* [RoomOptionsDefaults.reactions] to enable reactions with default options.
*/
val reactions: RoomReactionsOptions? = null,
/**
* The occupancy options for the room. To enable occupancy in the room, set this property. You may use
* [RoomOptionsDefaults.occupancy] to enable occupancy with default options.
*/
val occupancy: OccupancyOptions? = null,
) {
companion object {
/**
* Supports all room options with default values
*/
val default = RoomOptions(
typing = TypingOptions(),
presence = PresenceOptions(),
reactions = RoomReactionsOptions,
occupancy = OccupancyOptions,
)
}
}
/**
* Represents the presence options for a chat room.
*/
data class 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 [Presence.enter]
* in order to enter presence.
* @defaultValue true
*/
val enter: Boolean = true,
/**
* 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 [Presence.subscribe]
* in order to subscribe to presence.
* @defaultValue true
*/
val subscribe: Boolean = true,
)
/**
* Represents the typing options for a chat room.
*/
data class 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
*/
val timeoutMs: Long = 5000,
)
/**
* Represents the reactions options for a chat room.
*/
object RoomReactionsOptions
/**
* Represents the occupancy options for a chat room.
*/
object OccupancyOptions
/**
* Throws AblyException for invalid room configuration.
* Spec: CHA-RC2a
*/
fun RoomOptions.validateRoomOptions() {
typing?.let {
if (typing.timeoutMs <= 0) {
throw ablyException("Typing timeout must be greater than 0", ErrorCode.InvalidRequestBody)
}
}
}