Listening for Events

As soon as you call watch on a Channel or queryChannels you’ll start to listen to these events. You can hook into specific events:

// Subscribing via a UOBJECT member function
Channel->On<FMessageDeletedEvent>(this, &UMyObject::OnMessageDeleted);

// Subscribing via a lambda function
Channel->On<FMessageDeletedEvent>(
  [](const FMessageDeletedEvent& Event)
  {
    // Message was deleted
  });

You can also listen to all events at once: (Full list of events is on events object page)

// Not supported in the Unreal SDK

Client Events

Not all events are specific to channels. Events such as the user’s status has changed, the users’ unread count has changed, and other notifications are sent as client events. These events can be listened to through the client directly:

Client->On<FHealthCheckEvent>(this, &UMyObject::OnHealthCheck);
Client->On<FUserPresenceChangedEvent>(this, &UMyObject::OnUserPresenceChanged);

Connection Events

The official SDKs make sure that a connection to Stream is kept alive at all times and that chat state is recovered when the user’s internet connection comes back online. Your application can subscribe to changes to the connection using client events.

Client->On<FConnectionChangedEvent>(
  [](const FConnectionChangedEvent& Event)
  {
    if (Event.bOnline)
    {
      // Came online
    } else
    {
      // Went offline
    }
  });

Stop Listening for Events

It is a good practice to unregister event handlers once they are not in use anymore. Doing so will save you from performance degradations coming from memory leaks or even from errors and exceptions (i.e. null pointer exceptions)

// Subscribe
const FDelegateHandle Handle = Client->On<FHealthCheckEvent>(this, &UMyObject::OnHealthCheck);

// Unsubscribe
const bool bSuccess = Client->Unsubscribe<FHealthCheckEvent>(Handle);
© Getstream.io, Inc. All Rights Reserved.