Skip to main content
// Start typing indicator
const typing = new CometChat.TypingIndicator("UID", CometChat.RECEIVER_TYPE.USER);
CometChat.startTyping(typing);

// Stop typing indicator
CometChat.endTyping(typing);

// Listen for typing events
CometChat.addMessageListener("LISTENER_ID", new CometChat.MessageListener({
  onTypingStarted: (indicator) => console.log("Typing started:", indicator),
  onTypingEnded: (indicator) => console.log("Typing ended:", indicator)
}));

Send a Typing Indicator

Start Typing

Use startTyping() with a TypingIndicator object to notify the receiver that you’re typing.
let receiverId = "UID";
let receiverType = CometChat.RECEIVER_TYPE.USER;

let typingNotification = new CometChat.TypingIndicator(receiverId, receiverType);
CometChat.startTyping(typingNotification);  

Stop Typing

Use endTyping() to notify the receiver that you’ve stopped typing.
let receiverId = "UID";
let receiverType = CometChat.RECEIVER_TYPE.USER;

let typingNotification = new CometChat.TypingIndicator(receiverId, receiverType);
CometChat.endTyping(typingNotification);
Use setMetadata() on TypingIndicator to pass additional custom data. Retrieve it with getMetadata() on the receiver side.

Real-time Typing Indicators

Use onTypingStarted and onTypingEnded in MessageListener to receive typing events.
let listenerId = "UNIQUE_LITENER_ID";

CometChat.addMessageListener(
listenerId,
new CometChat.MessageListener({
  onTypingStarted: typingIndicator => {
    console.log("Typing started :", typingIndicator);
  },
  onTypingEnded: typingIndicator => {
    console.log("Typing ended :", typingIndicator);
  }
})
);
The TypingIndicator object contains:
ParameterDescription
senderUser object of the person typing
receiverIdUID or GUID of the receiver
receiverTypeCometChat.RECEIVER_TYPE.USER or GROUP
metadataAdditional custom data
The onTypingStarted and onTypingEnded listener callbacks receive a TypingIndicator object. Access the data using getter methods:
FieldGetterReturn TypeDescription
receiverIdgetReceiverId()stringUID or GUID of the typing indicator recipient
receiverTypegetReceiverType()stringType of receiver ("user" or "group")
sendergetSender()UserThe user who is typing
metadatagetMetadata()ObjectAdditional custom data sent with the indicator

Next Steps

Delivery & Read Receipts

Track when messages are delivered and read

Transient Messages

Send ephemeral real-time messages like live reactions