Skip to main content

Typing Indicator

Sending Typing Status Messages

When a user is typing a message, they can send a "typing" status notification to the recipient by calling the sendTypingStatusMessage method.

Interface

RongIMLib.sendTypingStatusMessage(conversation, typingContentType)

Parameters

ParameterTypeRequiredDescription
conversationIConversationOptionYesTarget conversation
typingContentTypestringYesTyping status message type. For built-in message type names in RC, refer to Message Type Overview.

Sample Code

const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "targetId"
}
RongIMLib.sendTypingStatusMessage(conversation, RongIMLib.MessageType.TEXT).then(res => {
// Typing status sent successfully
if ( res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
})

Setting Up Typing Status Event Listeners

Monitor changes in the recipient's "typing" status and obtain real-time updates about conversations with active typers through event callbacks.

API Reference: addEventListener

Sample Code

const Events = RongIMLib.Events;
function onTyping({ status }) {
// Multiple conversations may have active typers simultaneously
status.forEach((item) => {
const { targetId, conversationType, channelId, list } = item;
console.log(`Current active typing conversation:`, targetId, conversationType, channelId);

// Multiple users may be typing in the same conversation simultaneously (e.g., in groups)
// The 'list' contains all users currently typing in this conversation
list.forEach(({ userId, timestamp, messageType }) => {
// ...
})
})
}
RongIMLib.addEventListener(Events.TYPING_STATUS, onTyping);