/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Add or remove a connection event handler

Copy link

To detect changes in the connection status of a client app, add a connection event handler with its unique user-defined ID by calling AddConnectionHandler().

If you want to stay informed of changes related to the Sendbird server connection status and notify client apps of these changes, define and register multiple connection event handlers to each view controller.


Connection event types

Copy link

List of connection events

Copy link
MethodInvoked whenNotified devices

OnConnected()

The Chat SDK has been connected to the Sendbird server for the first time.

The device that is connected to the Sendbird server.

OnDisconnected()

The user has been logged out. It is different from WebSocket disconnection where a client app goes to the background. This handler is called after SendbirdChat.Disconnect() is called.

The device that is disconnected from the Sendbird server.

OnReconnectStarted()

The Chat SDK has started reconnecting to the Sendbird server.

The device where Connect() was automatically called by the Chat SDK, or manually by the client app.

OnReconnectSucceeded()

The Chat SDK has succeeded in reconnecting to the Sendbird server.

The device that successfully reconnected to the server.

OnReconnectFailed()

The Chat SDK has failed to reconnect to the Sendbird server.

The device that failed to reconnect to the server.


Add a connection event handler

Copy link

The following code shows a full set of supported event callbacks with their parameters and how to add a connection event handler to the SendbirdChat class.

SbConnectionHandler connectionHandler = new SbConnectionHandler
{
    OnConnected = (inUserId) => 
    { 
        // Action when connected
    },
    OnDisconnected = (inUserId) => 
    {
        // Action when disconnected
    },
    OnReconnectStarted = () => 
    {
        // Action when reconnection starts
    },
    OnReconnectSucceeded = () => 
    {
        // Action when reconnection succeeds
    },
    OnReconnectFailed = () => 
    {
        // Action when reconnection fails
    }
};

SendbirdChat.AddConnectionHandler("UNIQUE_HANDLER_ID", connectionHandler);

Remove a connection event handler

Copy link

The following code shows how to remove the connection event handler.

SendbirdChat.RemoveConnectionHandler("UNIQUE_HANDLER_ID");