The Agora SDK has reconnection mechanisms when a user drops offline or a process gets killed.This page shows the connection state mechanism of the Agora SDK under these circumstances.
The Agora SDK adds the onConnectionStateChanged
or connectionStateChangedToState
callback in v2.3.2. This callback reports the current network connection state and reasons to any state change.
The following diagram shows the callbacks received by the apps of UID 1 and UID 2 during which UID 1 joins the channel, experiences a network exception, loses connection, and rejoins the channel.
Where:
joinChannel
or joinChannelByToken
request from the app of UID 1.joinChannel
or joinChannelByToken
method, the app of UID 1 joins the channel and receives the onJoinChannelSuccess
or didJoinChannel
callback.onUserJoined
or didJoinedOfUid
callback.onConnectionInterrupted
or rtcEngineConnectionDidInterrupted
callback; meanwhile the SDK continues to try rejoining the channel.onConnectionLost
or rtcEngineConnectionDidLost
callback; meanwhile the SDK continue to try rejoining the channel.onUserOffline
or didOfflineOfUid
callback.onRejoinChannelSuccess
or didRejoinChannel
callback.onUserJoined
or didJoinOfUid callback
, which means that UID 1 is online again.The following diagram shows the callbacks received by the apps of UID 1 and UID 2 during which UID 1 joins the channel, experiences a network exception, loses connection, and eventually fails to rejoin the channel.
Where:
joinChannel
or joinChannelByToken
request from the app of UID 1.joinChannel
or joinChannelByToken
method, the app of UID 1 joins the channel. During the process, the app of UID 1 also receives the onConnectionStateChanged(CONNECTION_STATE_CONNECTING, CONNECTION_CHANGED_CONNECTING)
or connectionChangedToState(AgoraConnectionStateConnecting, AgoraConnectionChangedConnecting)
callback. When successfully joining the channel, app of UID 1 receives the onConnectionStateChanged(CONNECTION_STATE_CONNECTED, CONNECTION_CHANGED_JOIN_SUCCESS)
or connectionChangedToState(AgoraConnectionStateConnected, AgoraConnectionChangedJoinSuccess)
and onJoinChannelSuccess
or didJoinChannel
callbacks. onUserJoined
or didJoinedOfUid
callback.onConnectionStateChanged(CONNECTION_STATE_RECONNECTING, CONNECTION_CHANGED_INTERRUPTED)
or connectionChangedToState(AgoraConnectionStateReconnecting, AgoraConnectionChangedInterrupted)
callback; meanwhile the SDK continues to try rejoining the channel.onUserOffline
or didOfflineOfUid
callback.
- If UID 2 is a Web client, the behaviors of the Web app are as follows:
- When UID 1 joins and rejoins the channel, UID 2 receives the
client.on("stream-added")
callback.- If UID 2 does not receive any data from UID 1 in 10 seconds, UID 2 receives the
client.on("stream-removed")
callback.- If the server does not receive any data from UID 1 in 3 minutes, UID 2 receives the
client.on("peer-leave")
callback.- Users can call
leaveChannel
to stop the retires at any time during the SDK reconnection process.
This scenario involves the following situations:
Suppose UID 1 and UID 2 are in the same channel. When the process of user A gets killed:
If UID 1 is in iOS or macOS: UID 1 calls the leaveChannel
method and UID 2 receives a callback:
onUserOffline
callback.didOfflineOfUid
callback.client.on("peer-leave")
callback.If UID 1 is in Android, Windows, or Linux and user B uses the Native SDK:
If UID 1 does not restart the app and rejoin the original channel within 20 seconds, UID 2 receives a callback:
onUserOffline
callback.didOfflineOfUid
callback.If UID 1 restarts the app and rejoins the original channel within 20 seconds, UID 2 does not receive any callback function.
If UID 1 is in Android, Windows, or Linux and UID 2 uses the Web SDK:
client.on("stream-removed")
callback.For the Web SDK, killing a process is equivalent to a user dropping offline.
If UID 1 is the last user in the channel, the server destroys the channel in 10 seconds.