Typing indicator

The typing indicator feature provides real-time feedback when someone is composing a message, enhancing the conversational flow. It helps in the following:

  • Active participation - within group chats or collaborative environments, a user can measure others' engagement levels based on typing indicators, encouraging active involvement and minimizing communication gaps.

  • Anticipating responses - when engaged in 1:1 conversations, a user can see if the other person is actively responding, helping manage expectations and reducing uncertainty regarding response times.

Not available for public chats

Typing indicator is disabled in public chats. If you try implementing this feature in a public channel type, you'll get the Typing indicators are not supported in Public chats error.

Start typing

StartTyping() activates a typing indicator on a given channel.

The method sets a flag (typingSent) to indicate that a typing signal is in progress and adds a timer to reset the flag after a specified timeout.

The Unity Chat SDK has a default typing timeout set to 5000 milliseconds (5 seconds) during the Unity Chat SDK initialization. The StartTyping() method substracts 1000 milliseconds (1 second) from the default timeout to cause an intentional delay between typing signals ("debounce" period).

This debounce mechanism ensures that the system responds to a user's actual typing behavior without being overly sensitive to minor fluctuations, keypresses, or temporary pauses in typing. Thanks to that, the typing indicator reflects more deliberate typing actions rather than every keystroke.

Configure default timeout

You can change the default typing timeout and set your own value during the Unity Chat SDK configuration using the typingTimeout parameter.

Method signature

This method has the following signature:

channel.StartTyping()

Input

This method doesn't take any parameters.

Output

This method doesn't return any data.

Basic usage

Start a typing indicator on the support channel.

// reference the channel where you want to listen to typing signals
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
// invoke the "startTyping()" method
channel.StartTyping()

Stop typing

StopTyping() deactivates a typing indicator on a given channel.

You can use this method in cases when you want to disable the typing indicator immediately.

Method signature

This method has the following signature:

channel.StopTyping()

Input

This method doesn't take any parameters.

Output

This method doesn't return any data.

Basic usage

Stop a typing indicator on the support channel.

// reference the channel where you want to listen to typing signals
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
};
// invoke the "StopTyping()" method
channel.StopTyping()

Get typing events

Get up-to-date information about the real-time signals from typing users in the specified channel by subscribing to OnUsersTyping events. These events let you constantly track who has started or stopped typing and visually represent that in your chat app through a typing indicator.

Event signature

Action<List<string>> OnUsersTyping;

Event handler signature

void EventHandler(List<string> users)
ParameterTypeRequiredDefaultDescription
usersList<string>Yesn/aList of typing user IDs.

Basic usage

Get typing events on the support channel.

public void InitializeChat()
{
// reference the channel where you want to listen to typing signals
if (chat.TryGetChannel("support", out var channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");

// join the channel
channel.Join();

// subscribe to the OnUsersTyping event
channel.OnUsersTyping += OnUsersTypingHandler;

// sndicate that typing has started
channel.StartTyping();
show all 21 lines
Last updated on