In real-time communications, a user can be in various channel connection states. This page shows how the SDK determines the connection state of a user and transitions between the states.
To help you get the connection state of each user in the channel, the Agora Native SDK added the
onConnectionStateChanged callback in v2.3.0. This callback occurs when the connection state of the local user changes. You can get the connection state and reason for the state change in this callback.
With this callback, the SDK provides the following connection states of the users:
The following diagram shows how each connection state is defined:
During communications, you can also call the
getConnectionState method to get the current connection state, and the reason for the state change in the
When network interruption occurs, the SDK automatically tries reconnecting to the server.
The following diagram shows the callbacks received by UID 1 and UID 2, where UID 1 joins the channel, gets a network exception, loses connection, and rejoins the channel.
joinChannelrequest from UID 1.
joinChannelmethod, UID 1 joins the channel. During the process, UID 1 also receives the
onConnectionStateChanged(CONNECTION_STATE_CONNECTING, CONNECTION_CHANGED_CONNECTING)callback. When successfully joining the channel, UID 1 receives the
onConnectionStateChanged(CONNECTION_STATE_RECONNECTING, CONNECTION_CHANGED_INTERRUPTED)callback; meanwhile the SDK continues to try rejoining the channel.
onConnectionStateChanged(CONNECTION_STATE_RECONNECTING, CONNECTION_CHANGED_INTERRUPTED), UID 1 receives the
onConnectionLostcallback; meanwhile the SDK continue to try rejoining the channel.
onConnectionStateChanged(CONNECTION_STATE_RECONNECTING, CONNECTION_CHANGED_INTERRUPTED), the SDK stops trying. UID 1 receives the
onConnectionStateChanged(CONNECTION_STATE_FAILED, CONNECTION_CHANGED_JOIN_FAILED)callback. UID 1 needs to leave the channel and call the
joinChannelmethod to join the channel.
leaveChannelto stop the retires at any time during the SDK reconnection process.
For the reconnection mechanism in Agora Native SDKs earlier than v2.3.2, and how connection states change when the process gets killed, see FAQ: Does Agora have reconnection mechanisms?