Skip to content

Commit 5c4eaf9

Browse files
authored
Merge pull request #2569 from ably/integration/chat-single-channel
Chat single channel updates
2 parents 4f43d72 + 8a45af4 commit 5c4eaf9

File tree

11 files changed

+128
-115
lines changed

11 files changed

+128
-115
lines changed

content/chat/connect.textile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ If a client briefly loses connection to Ably, for example when driving through a
144144
During periods of discontinuity greater than 2 minutes then you will need to take steps to recover any missed messages, such as by calling "history":/docs/chat/rooms/history.
145145

146146
blang[javascript,swift,kotlin].
147-
Each feature of the Chat SDK provides an @onDiscontinuity()@ handler to assist with this. These methods enable you to register a listener that will be notified when discontinuity occurs in that feature so that you can handle it, as needed.
147+
The Chat SDK provides an @onDiscontinuity()@ handler exposed via the Room object to assist with this. This method enables you to register a listener that will be notified when discontinuity occurs in the room so that you can handle it, as needed.
148148

149149
blang[react].
150150
Any hooks that take an optional listener to monitor their events, such as typing indicator events in the @useTyping@ hook, can also register a listener to be notified of, and handle, periods of discontinuity.
151151

152152
For example, for messages:
153153

154154
```[javascript]
155-
const { off } = room.messages.onDiscontinuity((reason?: ErrorInfo) => {
155+
const { off } = room.onDiscontinuity((reason: ErrorInfo) => {
156156
// Recover from the discontinuity
157157
});
158158
```
@@ -173,14 +173,14 @@ const MyComponent = () => {
173173
```
174174

175175
```[swift]
176-
let subscription = room.messages.onDiscontinuity()
176+
let subscription = room.onDiscontinuity()
177177
for await error in subscription {
178178
print("Recovering from the error: \(error)")
179179
}
180180
```
181181

182182
```[kotlin]
183-
val subscription = room.messages.onDiscontinuity { reason: ErrorInfo? ->
183+
val subscription = room.onDiscontinuity { reason: ErrorInfo ->
184184
// Recover from the discontinuity
185185
}
186186
```
@@ -207,10 +207,4 @@ blang[react,swift].
207207
blang[react].
208208

209209
blang[javascript,swift,kotlin].
210-
The following discontinuity handlers are available:
211-
212-
* <span lang="javascript">"Messages":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#onDiscontinuity</span><span lang="swift">"Messages":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages</span>
213-
* <span lang="javascript">"Presence":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Presence.html#onDiscontinuity</span><span lang="swift">"Presence":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/presence</span>
214-
* <span lang="javascript">"Occupancy":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Occupancy.html#onDiscontinuity</span><span lang="swift">"Occupancy":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/occupancy</span>
215-
* <span lang="javascript">"Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#onDiscontinuity</span><span lang="swift">"Typing indicators":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing</span>
216-
* <span lang="javascript">"Room reactions":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomReactions.html#onDiscontinuity</span><span lang="swift">"Room reactions":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomreactions</span>
210+
The discontinuity handler is accessible via the <span lang="javascript">"Room":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Room.html#onDiscontinuity</span><span lang="swift">"Room":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/room</span><span lang="kotlin">"Room":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-room/index.html</span> object.

content/chat/getting-started/javascript.textile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ h2(#step-5). Step 5: Show who is typing a message
163163

164164
Typing indicators enable you to display messages to clients when someone is currently typing. An event is emitted when someone starts typing, when they press a keystroke, and then another event is emitted after a configurable amount of time has passed without a key press.
165165

166-
In practice the @typing.start()@ method would be called on keypress, however for demonstration purposes we will call it and wait for the default period of time to pass for a stop event to be emitted. Using your original client, add the following lines to @getStarted()@ to subscribe to typing events and emit one, then run it with @npx ts-node index.ts@:
166+
In practice the @typing.keystroke()@ method would be called on keypress, however for demonstration purposes we will call it and wait for the default period of time to pass for a stop event to be emitted. Using your original client, add the following lines to @getStarted()@ to subscribe to typing events and emit one, then run it with @npx ts-node index.ts@:
167167

168168
```[javascript]
169169
room.typing.subscribe((typingEvent) => {
@@ -174,7 +174,7 @@ room.typing.subscribe((typingEvent) => {
174174
}
175175
});
176176

177-
await room.typing.start()
177+
await room.typing.keystroke()
178178
// A client types
179179
await room.typing.stop()
180180
```

content/chat/rooms/index.textile

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,36 @@ languages:
1111

1212
Rooms are used to organize and logically separate your users and chat messages into 'rooms'. They are the entry object into using chat and provide access to all other chat features, such as messages, online status and typing indicators. A room can represent a 1:1 chat between an agent and a customer, a private message between two users in a chat application, a large group conversation, or the chat section of a livestream with thousands of users.
1313

14-
You also control which features are enabled in a room when you create one. For instance, you might only want to utilize typing indicators in direct messages between users.
14+
h2(#channel-relationship). Channel <> Room relationship
15+
16+
It is important to note that each room is backed by a single Ably Pub/Sub channel. You may need to be aware of this when using some integrations with Ably, such as the "Pulsar":https://ably.com/docs/integrations/streaming/pulsar#creating-pulsar-rule connectors, or if you are operating in an environment where a Chat SDK is not available.
17+
18+
The channel name is the same as the room ID with an appended suffix of @::$chat@ (e.g @some-room-id::$chat@). In most cases, you will not need to worry about this, as the Chat SDK handles the channel creation and management for you and capabilities can be configured at the room level.
19+
1520

1621
h2(#create). Create or retrieve a room
1722

18-
Users send messages to a room and subscribe to the room in order to receive messages. Other features, such as indicating which users are online, or which users are typing are configured as part of a room's options.
23+
Users send messages to a room and subscribe to the room in order to receive messages.
1924

2025
blang[javascript,swift,kotlin].
2126
A @room@ is created, or an existing one is retrieved from the @rooms@ collection using the <span lang="javascript">"@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#get</span><span lang="swift">"@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/rooms/get%28roomid%3Aoptions%3A%29</span><span lang="kotlin">"@rooms.get()@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-rooms/get.html</span> method:
2227

2328
blang[react].
2429
The "@ChatRoomProvider@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.ChatRoomProvider.html provides access to a specific chat room to all child components in the component tree.
2530

26-
Pass in the ID of the room to use, and select which which additional chat features you want enabled for that room. This is configured by passing a "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html object to the provider.
31+
Pass in the ID of the room to use. If you need to provide further feature configuration, such as enabling occupancy messages, you can pass in an optional "@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html object to the provider.
2732

2833
<aside data-type='note'>
2934
<p>All components that utilize chat feature hooks must be children of a @ChatRoomProvider@. This includes @useRoom@, "@useMessages@":/docs/chat/rooms/messages, "@useOccupancy@":/docs/chat/rooms/occupancy, "@usePresence@":/docs/chat/rooms/presence, "@usePresenceListener@":/docs/chat/rooms/presence, "@useRoomReactions@":/docs/chat/rooms/reactions and "@useTyping@":/docs/chat/rooms/typing.</p>
3035
</aside>
3136

3237
```[javascript]
33-
const room = await chatClient.rooms.get('basketball-stream', AllFeaturesEnabled);
38+
const room = await chatClient.rooms.get('basketball-stream', {occupancy: {enableEvents: true}});
3439
```
3540

3641
```[react]
3742
import * as Ably from 'ably';
38-
import { LogLevel, AllFeaturesEnabled } from '@ably/chat';
43+
import { LogLevel } from '@ably/chat';
3944
import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/react';
4045

4146
const realtimeClient = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'clientId' });
@@ -46,7 +51,7 @@ const App = () => {
4651
<ChatClientProvider client={chatClient}>
4752
<ChatRoomProvider
4853
id="my-room-id"
49-
options={AllFeaturesEnabled}
54+
options={{occupancy: {enableEvents: true}}}
5055
>
5156
<RestOfYourApp />
5257
</ChatRoomProvider>
@@ -56,11 +61,11 @@ const App = () => {
5661
```
5762

5863
```[swift]
59-
let room = try await chatClient.rooms.get(roomID: "basketball-stream", options: RoomOptions())
64+
let room = try await chatClient.rooms.get(roomID: "basketball-stream", options: .init(occupancy: .init(enableEvents: true)))
6065
```
6166

6267
```[kotlin]
63-
val room = chatClient.rooms.get(roomId = "basketball-stream", options = RoomOptions())
68+
val room = chatClient.rooms.get(roomId = "basketball-stream")
6469
```
6570

6671
blang[react].
@@ -71,67 +76,50 @@ blang[react].
7176
</aside>
7277

7378
blang[javascript,swift,kotlin].
74-
When you create or retrieve a room using @rooms.get()@, you need to choose which additional chat features you want enabled for that room. This is configured by passing a <span lang="javascript">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html</span><span lang="swift">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomoptions</span><span lang="kotlin">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-room-options/index.html</span> object as the second argument. In addition to setting which features are enabled, @RoomOptions@ also configures the properties of the associated features, such as the timeout period for typing indicators.
79+
When you create or retrieve a room using @rooms.get()@, you can provide custom configuration for some features for that room by passing a <span lang="javascript">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.RoomOptions.html</span><span lang="swift">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/roomoptions</span><span lang="kotlin">"@RoomOptions@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-room-options/index.html</span> object as the second argument. If you do not provide a @RoomOptions@ object, the default settings will be used.
7580

7681
```[javascript]
77-
const presence = {enter: false};
78-
const reactions = {};
79-
const occupancy = {};
8082
const typing = {timeoutMs: 5000};
8183
const room = await chatClient.rooms.get('basketball-stream', {presence, reactions, typing, occupancy});
8284
```
8385

8486
```[swift]
8587
let presence = PresenceOptions(enter: false)
86-
let typing = TypingOptions(timeout: 5.0) // seconds
88+
let typing = TypingOptions(heartbeatThrottle: 5.0) // seconds
8789
// using defaults for reactions and occupancy
88-
let options = RoomOptions(presence: presence, typing: typing, reactions: nil, occupancy: nil)
90+
let options = RoomOptions(presence: presence, typing: typing, reactions: .init(), occupancy: .init())
8991
let room = try await chatClient.rooms.get(roomID: "basketball-stream", options: options)
9092
```
9193

9294
```[kotlin]
93-
val presence = PresenceOptions(enter = false)
94-
val typing = TypingOptions(timeoutMs = 5_000) // 5 seconds
95-
val options = RoomOptions(presence = presence, typing = typing)
96-
val room = chatClient.rooms.get(roomId = "basketball-stream", options = options)
97-
```
98-
99-
blang[javascript].
100-
You can also use the @AllFeaturesEnabled@ property for each @RoomOption@ to configure whether preconfigured example settings should be used:
101-
102-
```[javascript]
103-
const room = await chatClient.rooms.get('basketball-stream', {presence: AllFeaturesEnabled.presence});
104-
```
105-
106-
Or configure each feature using your own values:
107-
108-
```[javascript]
109-
const room = await chatClient.rooms.get('basketball-stream', {typing: {timeoutMs: 5000}});
95+
val room = chatClient.rooms.get(roomId = "basketball-stream") {
96+
typing {
97+
heartbeatThrottle = 5.seconds
98+
}
99+
presence {
100+
enableEvents = true
101+
}
102+
occupancy {
103+
enableEvents = true
104+
}
105+
}
110106
```
111107

112108
blang[react,swift,kotlin].
113109

114-
Enable each feature using its associated option. The details of the options available to each feature are documented on their respective pages:
110+
The details of the options available to each feature are documented on their respective pages:
115111

116-
blang[javascript].
117-
| Feature | @RoomOption@ | Default settings |
118-
| "Presence":/docs/chat/rooms/presence | @presence@ | @AllFeaturesEnabled.presence@ |
119-
| "Occupancy":/docs/chat/rooms/occupancy | @occupancy@ | @AllFeaturesEnabled.occupancy@ |
120-
| "Typing indicators":/docs/chat/rooms/typing | @typing@ | @AllFeaturesEnabled.typing@ |
121-
| "Room reactions":/docs/chat/rooms/reactions | @reactions@ | @AllFeaturesEnabled.reactions@ |
122-
123-
blang[swift,kotlin].
112+
blang[javascript,swift,kotlin].
124113
| Feature | @RoomOption@ | Default settings |
125-
| "Presence":/docs/chat/rooms/presence | @presence@ | @PresenceOptions()@ |
126-
| "Occupancy":/docs/chat/rooms/occupancy | @occupancy@ | @OccupancyOptions()@ |
127-
| "Typing indicators":/docs/chat/rooms/typing | @typing@ | @TypingOptions()@ |
128-
| "Room reactions":/docs/chat/rooms/reactions | @reactions@ | @RoomReactionsOptions()@ |
114+
| "Presence":/docs/chat/rooms/presence | @presence.enableEvents@ | @true@ |
115+
| "Occupancy":/docs/chat/rooms/occupancy | @occupancy.enableEvents@ | @false@ |
116+
| "Typing indicators":/docs/chat/rooms/typing | @typing.heartbeatThrottleMs@ | @10000@ |
129117

130118
h3(#release). Release a room
131119

132120
Releasing a room allows the underlying resources to be garbage collected or released.
133121

134-
Releasing a room may be optional for many applications. If you have multiple transient rooms, such as in the case of a 1:1 support chat, then it is may be more beneficial.
122+
Releasing a room may be optional for many applications. If you have multiple transient rooms, such as in the case of a 1:1 support chat, then it may be more beneficial. Also, proactively disconnecting rather than waiting for the standard two-minute timeout can help reduce costs and improve performance.
135123

136124
blang[javascript,swift,kotlin].
137125
Once <span lang="javascript">"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Rooms.html#release</span><span lang="swift">"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/rooms/release%28roomid%3A%29</span><span lang="kotlin">"@rooms.release()@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-rooms/release.html</span> has been called, the room will be unusable and a new instance will need to be created using "@rooms.get()@":#create if you want to reuse it.

content/chat/rooms/messages.textile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const MyComponent = () => {
305305

306306
```[swift]
307307
let messagesList: [Message]
308-
let messagesSubscription = try await room().messages.subscribe()
308+
let messagesSubscription = try await room.messages.subscribe()
309309
for await message in messagesSubscription {
310310
switch message.action {
311311
case .create:
@@ -415,7 +415,7 @@ const MyComponent = () => {
415415

416416
```[swift]
417417
let messageToDelete: Message
418-
let deletedMessage = try await room().messages.delete(
418+
let deletedMessage = try await room.messages.delete(
419419
message: messageToDelete,
420420
params: .init(description: "Message deleted by user")
421421
)
@@ -492,7 +492,7 @@ const MyComponent = () => {
492492

493493
```[swift]
494494
let messagesList: [Message]
495-
let messagesSubscription = try await room().messages.subscribe()
495+
let messagesSubscription = try await room.messages.subscribe()
496496
for await message in messagesSubscription {
497497
switch message.action {
498498
case .create:

content/chat/rooms/occupancy.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ languages:
1212
Occupancy enables you to view the number of users currently online in a room. This feature can be used to display user counts to highlight popular, or trending chat rooms.
1313

1414
<aside data-type='note'>
15-
<p>Occupancy needs to be "enabled":/docs/chat/rooms#create when creating or retrieving a room.</p>
15+
<p>Occupancy generates messages on any client entering/leaving a room, and so increases the number of billable messages sent in a room - as such, it is disabled by default and needs to be "enabled":/docs/chat/rooms#create when creating or retrieving a room.</p>
1616
</aside>
1717

1818
h2(#subscribe). Subscribe to room occupancy

content/chat/rooms/presence.textile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ languages:
1111

1212
Subscribe to the online status of room members using the presence feature. Presence enables you to show which members are currently online, indicate when a user goes offline, and have users optionally set additional information about their profile, or their current status within the application.
1313

14-
<aside data-type='note'>
15-
<p>Presence needs to be "enabled":/docs/chat/rooms#create when creating or retrieving a room.</p>
16-
</aside>
17-
1814
h2(#subscribe). Subscribe to presence
1915

2016
blang[javascript,swift,kotlin].
@@ -297,16 +293,10 @@ h2(#options). Presence options
297293

298294
The following options can be set when "creating a room":/docs/chat/rooms#create that are specific to presence:
299295

300-
blang[javascript].
301-
302-
|_. Property |_. Description |_. Default |
303-
| enter | Set whether the client has permissions to enter the presence set. Calling @presence.enter()@ is still required. | true |
304-
| subscribe | Set whether the client has permissions to subscribe to the presence set. Calling @presence.subscribe()@ is still required. | true |
305-
306-
blang[react].
296+
blang[javascript,react].
307297

308298
|_. Property |_. Description |_. Default |
309-
| subscribe | Set whether the client has permissions to subscribe to the presence set. Calling @presence.subscribe()@ is still required. | true |
299+
| enableEvents | Set whether the client has permissions to subscribe to the presence set. Calling @presence.subscribe()@ is still required. | true |
310300

311301
h2(#retrieve). Retrieve the presence set
312302

content/chat/rooms/reactions.textile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ Users can send reactions to the entire chat room to show their sentiment as to w
1313

1414
Room reactions are ephemeral and not stored or aggregated by Ably. The intention being that they show the overall sentiment of a room at a point in time.
1515

16-
<aside data-type='note'>
17-
<p>Room reactions need to be "enabled":/docs/chat/rooms#create when creating or retrieving a room.</p>
18-
</aside>
19-
2016
h2(#subscribe). Subscribe to room reactions
2117

2218
blang[javascript,swift,kotlin].

0 commit comments

Comments
 (0)