You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/chat/rooms/typing.textile
+54-12Lines changed: 54 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,13 +72,20 @@ The following is the structure of a typing event:
72
72
"clemons",
73
73
"zoranges",
74
74
},
75
+
"change": {
76
+
"type": "typing.started",
77
+
"clientId": "clemons"
78
+
}
75
79
}
76
80
```
77
81
78
82
The following are the properties of a typing event:
79
83
80
84
|_. Property |_. Description |_. Type |
81
85
| currentlyTyping | A set of all users currently typing. | Set |
86
+
| change | The single change that resulted in the event. | Object |
87
+
| | type: The type of change that occurred. | String |
88
+
| | clientId: The @clientId@ of the user that triggered the change. | String |
82
89
83
90
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.
Use the <span lang="javascript">"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#start</span><span lang="swift">"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/start%28%29</span><span lang="kotlin">"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-typing/start.html</span> method to emit a typing event with @isTyping@ set to @true@.
136
+
Use the <span lang="javascript">"@typing.keystroke()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Typing.html#start</span><span lang="swift">"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/typing/start%28%29</span><span lang="kotlin">"@typing.start()@":https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat-android/com.ably.chat/-typing/start.html</span> method to emit a typing event with @type@ set to @typing.started@.
129
137
130
138
blang[react].
131
-
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.
132
-
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.
139
+
Use the "@keystroke()@":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseTypingResponse.html#keystroke method available from the response of the @useTyping@ hook to emit an event when a user has started typing.
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 @keystroke()@, 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 @keystroke()@ 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
+
You can emulate user behavior (e.g., in chatbots) by setting a timeout to call @keystroke()@ 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
+
202
244
h2(#retrieve). Retrieve a list of users that are currently typing
203
245
204
246
blang[javascript,swift,kotlin].
205
247
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:
0 commit comments