Typing indicator

Typing indicators enable you to indicate if users are typing messages in a channel. This feature is easy to implement and can significantly improve the experience for your users.

You can trigger a typing event when a user starts typing a message. Other users in the channel receive these events in real time to show typing indicators on the screen. Applications usually display a typing indicator for a few seconds before it expires, or continue display it if the user is still typing. The app hides the indicator when it receives the actual message.

For example, you could follow a pattern like this:

  • Send a typing_on event when the user starts typing.
  • Send another typing_on event if the user is still typing after 10 to 15 seconds.
  • Send a typing_off event if the user removes the message they were typing.

Send typing on/off events

Use the signal method to send transient events to indicate that a user is typing a message or has stopped typing.

By default, signals are limited to a message payload size of 64 bytes. This limit applies only to the payload, and not to the URI or headers. If you require a larger payload size, contact support. For more details on working with signals, refer to Sending Signals.

pubnub.signal({
message: 'typing_on',
channel: 'ch-1'
}, (status, response) => {
// handle status, response
});

Note that signals are transient, and are handled differently than regular messages. You can't fetch signals from Message Persistence, and you only receive the most recent signal from the buffer queue via a subscribe request.

Typing Indicator Events

Typing events are published on the same channel as the original message. To receive them, you subscribe to the channel and add a listener for signals.

{
"actualChannel": null,
"channel": "ch-1",
"message": "typing_on",
"publisher": "user-456",
"subscribedChannel": "my_channel_1",
"subscription": null,
"timetoken": "14966804541029440"
}
Last updated on