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
connectionChangedToState 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.
joinChannelByTokenrequest from UID 1.
joinChannelByTokenmethod, UID 1 joins the channel. During the process, UID 1 also receives the
connectionChangedToState(AgoraConnectionStateConnecting, AgoraConnectionChangedConnecting)callback. When successfully joining the channel, UID 1 receives the
connectionChangedToState(AgoraConnectionStateReconnecting, AgoraConnectionChangedInterrupted)callback; meanwhile the SDK continues to try rejoining the channel.
connectionChangedToState(AgoraConnectionStateReconnecting, AgoraConnectionChangedInterrupted), UID 1 receives the
rtcEngineConnectionDidLostcallback; meanwhile the SDK continue to try rejoining the channel.
connectionChangedToState(AgoraConnectionStateReconnecting, AgoraConnectionChangedInterrupted), the SDK stops trying. UID 1 receives the
connectionChangedToState(AgoraConnectionStateFailed, AgoraConnectionChangedJoinFailed)callback. UID 1 needs to leave the channel and call the
joinChannelByTokenmethod 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?