Skip to content

Commit 4556d08

Browse files
committed
Broken the large block of text into sections to improve readability.
1 parent 1eaf703 commit 4556d08

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

content/chat/rooms/typing.textile

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ blang[react].
106106
blang[javascript,kotlin].
107107
```[javascript]
108108
// Initial subscription
109-
const { unsubscribe } = room.typing.subscribe((event) => {
109+
import { TypingEvent } from '@ably/chat';
110+
const { unsubscribe } = room.typing.subscribe((event: TypingEvent) => {
110111
console.log('Typing event received: ', event);
111112
});
112113

@@ -137,16 +138,6 @@ blang[javascript,swift,kotlin].
137138
blang[react].
138139
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.
139140

140-
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 @heartbeatThrottleMs@ parameter that can be configured in the @RoomOptions@ that you set when you "create a room":/docs/chat/rooms#create. The default is 10000ms.
141-
142-
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.
143-
144-
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 12000ms.
145-
146-
<aside data-type='note'>
147-
<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>
148-
</aside>
149-
150141
```[javascript]
151142
await room.typing.start();
152143
```
@@ -214,6 +205,42 @@ try await room.typing.stop()
214205
room.typing.stop()
215206
```
216207

208+
h3(#frequency). Typing Event Frequency
209+
210+
The Typing feature includes a configurable timer that controls how often typing events are sent to the server. This timer is reset each time a new typing event is sent, it works as follows:
211+
- On the **first call** to @start()@, the timer is set and an event is sent to the server.
212+
- **Subsequent calls** before the timer expires result in a no-op.
213+
- After the timer expires, a new typing event is sent and the timer is reset.
214+
- If @stop()@ is called, the timer is reset and a @typing.stopped@ event is sent to the server.
215+
216+
You can configure the length of this timer using the @heartbeatThrottleMs@ parameter in @RoomOptions@ (default: **10,000ms**).
217+
It is recommended that you call @start()@ with every keypress, and the SDK will handle when and if to send a typing indicator to the server.
218+
219+
h3(#emulating-heartbeats). Emulating User Behavior
220+
221+
If needed, you can emulate user behavior (e.g., in chatbots) by setting a timeout to call @start()@ at intervals equal to the @heartbeatThrottleMs@ plus a small delay, e.g. 200ms. This will ensure the typing indicator remains active.
222+
223+
h3(#grace-period). Grace Period for Typing Events
224+
225+
For the recipient of typing events:
226+
- The typing indicator remains active for the **duration** defined by the @heartbeatThrottleMs@ parameter, plus a predefined **2000ms grace period**.
227+
- Receiving a new typing event before the grace period ends will reset the timeout.
228+
- If the grace period ends without receiving a new typing event, the SDK will emit a @typing.stopped@ event for that client to any subscribed listeners.
229+
230+
**For example:** With the @heartbeatThrottleMs@ set to **10,000ms**, the typing indicator remains active for **12,000ms**. If no new typing event is received within this time, the SDK will emit a @typing.stopped@ event.
231+
232+
h3(#adjusting-timeout). Adjusting the Event Frequency
233+
234+
You can adjust the @heartbeatThrottleMs@ parameter to balance responsiveness and resource costs:
235+
- **Increase responsiveness**: Lower the value → More typing events are sent to the server → Higher cost as more messages are sent.
236+
- **Save resource costs**: Raise the value → Fewer typing events are sent to the server → Lower responsiveness, but less cost as fewer messages are sent overall.
237+
238+
This balance allows you to optimize cost and responsiveness based on your applications needs.
239+
240+
<aside data-type='note'>
241+
<p>All clients in a room must have the same timeout value configured. If not, typing indicators might not display correctly.</p>
242+
</aside>
243+
217244
h2(#retrieve). Retrieve a list of users that are currently typing
218245

219246
blang[javascript,swift,kotlin].
@@ -224,7 +251,7 @@ blang[javascript,swift,kotlin].
224251
```
225252

226253
```[swift]
227-
let currentlyTypingClientIds = try room.typing.get()
254+
let currentlyTypingClientIds = try await room.typing.get()
228255
```
229256

230257
```[kotlin]

0 commit comments

Comments
 (0)