Skip to main content

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)
}
})
ParameterTypeDescription
conversationObjectConversation object. See conversation Parameter Description below.
typingContentTypeStringThe 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 Description

    ParameterTypeRequiredDescription
    targetIdStringYesThe userId of the recipient
    conversationTypeNumberYesConversation 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);