Skip to content

Commit 65e6f60

Browse files
committed
Chat: Update typing indicator API documentation
Typing is no longer presence-based, the docs have been updated to reflect changes in logic to support this. - Also added details about the new `change` property in typing events and updated the timeout behavior with `start()` calls and grace periods. - `typing.get()` is also now synchronous.
1 parent 91c6179 commit 65e6f60

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

content/chat/rooms/typing.textile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,18 @@ The following is the structure of a typing event:
7272
"clemons",
7373
"zoranges",
7474
},
75+
"change": {
76+
"event": "typing.started",
77+
"clientId": "clemons"
78+
}
7579
}
7680
```
7781

7882
The following are the properties of a typing event:
7983

8084
|_. Property |_. Description |_. Type |
8185
| currentlyTyping | A set of all users currently typing. | Set |
86+
| change | The single change that resulted in the event. | Object |
8287

8388
You can use the size of the @currentlyTyping@ set to decide whether to display individual user names, or that multiple people are typing in your user interface.
8489

@@ -100,7 +105,7 @@ blang[javascript,kotlin].
100105
```[javascript]
101106
// Initial subscription
102107
const { unsubscribe } = room.typing.subscribe((event) => {
103-
console.log(`${event.clientId} is currently typing...`);
108+
console.log('Typing event received: ', event);
104109
});
105110

106111
// To remove the listener
@@ -130,7 +135,15 @@ blang[javascript,swift,kotlin].
130135
blang[react].
131136
Use the "@start()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#start method available from the response of the @useTyping@ hook to emit an event when a user has started typing.
132137

133-
There is a timeout associated with start events. A stop event will be automatically emitted after it expires if one isn't received before the timeout. The length of this timeout is customizable using the @timeoutMs@ parameter that can be configured in the @RoomOptions@ that you set when you "create a room":/docs/chat/rooms#create. The default is 10000ms.
138+
There is a timeout associated with start events. On first calling `start()`, this timer is set, subsequent calls to `start()` before the timer expires will result in a no-op. The length of this timeout is customizable using the @heartbeatIntervalMs@ parameter that can be configured in the @RoomOptions@ that you set when you "create a room":/docs/chat/rooms#create. The default is 15000ms.
139+
140+
Consequently, if you want to keep the typing indicator active, you should call `start()` with each key press to ensure a new typing event is emitted after the timeout has expired.
141+
142+
For a client receiving typing events, the typing indicator they have received will remain active for the duration of the timeout, plus a predefined grace period of 2000ms. If a new typing event is received for the same user before the grace period has expired, the typing indicator will be reset to the full duration of the timeout. For example, if the timeout is 15000ms, the typing indicator will remain active for 17000ms.
143+
144+
<aside data-type='note'>
145+
<p>It is important for all clients in a room to have the same timeout value set, otherwise the typing indicators may not be displayed correctly.</p>
146+
</aside>
134147

135148
```[javascript]
136149
await room.typing.start();
@@ -205,11 +218,11 @@ blang[javascript,swift,kotlin].
205218
Use the <span lang="javascript">"@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#get</span><span lang="swift">"@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/get%28%29</span><span lang="kotlin">"@typing.get()@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-typing/get.html</span> method to retrieve a set of @clientId@s for all users that are currently typing in the room:
206219

207220
```[javascript]
208-
const currentlyTypingClientIds = await room.typing.get();
221+
const currentlyTypingClientIds = room.typing.get();
209222
```
210223

211224
```[swift]
212-
let currentlyTypingClientIds = try await room.typing.get()
225+
let currentlyTypingClientIds = try room.typing.get()
213226
```
214227

215228
```[kotlin]

0 commit comments

Comments
 (0)