Typing Indicator
Sending Typing Status
When a user is typing, send a typing status message to the recipient.
API Reference: sendTypingStatusMessage - Sends a typing status message to the recipient.
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "targetId"
}
RongIMLib.sendTypingStatusMessage(conversation, RongIMLib.MessageType.TEXT).then(res => {
// Successfully sent typing status
if ( res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})
Parameter | Type | Description |
---|---|---|
conversation | Object | Conversation object. See conversation Parameter Description below. |
typingContentType | String | The type of message being typed. For text messages, pass the type name "RC:TxtMsg". For built-in message type names, see Message Type Overview. |
-
conversation
Parameter DescriptionParameter Type Required Description targetId String Yes The userId of the recipient conversationType Number Yes Conversation type, refer to ConversationType.
Setting Up Typing Status Event Listener
API Reference: addEventListener
const Events = RongIMLib.Events;
function onTyping({ status }) {
// Multiple conversations may have users typing at the same time
status.forEach((item) => {
const { targetId, conversationType, channelId, list } = item;
console.log(`Current typing conversations:`, targetId, conversationType, channelId);
// Multiple users may be typing in the same conversation at the same time, such as in a group;
// list contains the users currently typing in this conversation
list.forEach(({ userId, timestamp, messageType }) => {
// ...
})
})
}
RongIMLib.addEventListener(Events.TYPING_STATUS, onTyping);