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 connectionChangedToState
callback.
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.
Where:
joinChannelByToken
request from UID 1.joinChannelByToken
method, 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(AgoraConnectionStateConnected, AgoraConnectionChangedJoinSuccess)
and didJoinChannel
callbacks.didJoinedOfUid
callback.connectionChangedToState(AgoraConnectionStateReconnecting, AgoraConnectionChangedInterrupted)
callback; meanwhile the SDK continues to try rejoining the channel.rtcEngineConnectionDidLost
callback; meanwhile the SDK continue to try rejoining the channel.didOfflineOfUid
callback.connectionChangedToState(AgoraConnectionStateFailed, AgoraConnectionChangedJoinFailed)
callback. UID 1 needs to leave the channel and call thejoinChannelByToken
method to join the channel.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?