Connection status management
Updated
Test network quality and adjust audio and video settings to optimize channel quality
Supported platforms: Web, Android, iOS, macOS, Windows, Unreal Engine, Electron, Flutter, React Native, Unity, and Unreal Blueprint.
In real-time audio and video implementations, the connection state between the app and Agora SDRTN® changes as the client joins or leaves the channel. The connection may also be interrupted due to network or authentication issues.
This page describes the various channel connection states, reasons for state changes, and how to handle these changes to better manage your users and troubleshoot network faults.
Understand the tech
The following figure shows the various connection states and how the connection state changes between a user joining and leaving a channel:
Disconnection and reconnection
During the communication process, if the user is disconnected due to network problems, the SDK automatically enables the disconnection and reconnection mechanism. The following figure shows the callbacks received by the local user UID1 and the remote user UID2 when:
- A local user joins the channel
- A network exception occurs
- The connection is interrupted
- The user rejoins the channel
The following platform-specific timelines explain the reconnection sequence in detail.
In the diagram:
-
T0: The RTC SDK receives a
Client.joinrequest fromUID1. -
T1:
UID1successfully joins the channel.UID1receivesAgoraRTCClient.on("connection-state-change")callback reporting "CONNECTING" during joining channel and "CONNECTED" after joining. -
T2: Due to the transmission delay between networks,
UID2observes a delay of about 100 milliseconds forUID1to join the channel, and at this pointUID2receives aAgoraRTCClient.on("user-joined")callback. -
T3: At some point
UID 1callsAgoraRTCClient.publishto publish the local track. -
T4:
UID 2receives theAgoraRTCClient.on("user-published")callback indicating thatUID 1has published the track.UID 2can subscribe toUID 1's track by callingAgoraRTCClient.subscribemethod. -
T5: If the
UID 1network is interrupted during the communication process, the SDK automatically opens the disconnection and reconnection mechanism. -
T6: The SDK triggers
AgoraRTCClient.on("connection-state-change")callback to report "RECONNECTING" during automatic reconnection. -
T7: If the Agora server does not receive the audio/video packet from
UID 1for 10 consecutive seconds, the server determines thatUID 1no longer publishes audio/video, andUID 2will receiveAgoraRTCClient.on("user-unpublished")callback. -
T8: If the Agora server does not receive a heartbeat packet from
UID 1for 20 consecutive seconds, the server determines thatUID 1is offline, andUID 2will receive theAgoraRTCClient.on("user-left")callback. -
T9: After successfully re-establishing the connection,
UID 1receives theAgoraRTCClient.on("connection-state-change")callback reporting as "CONNECTED". -
T10:
UID 2receives theAgoraRTCClient.on("user-joined")callback again.
Prerequisites
Ensure that you have implemented the SDK quickstart project.
Implement connection status management
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
Connection states
The app may have the following connection states before joining, during a session, and after leaving a channel:
| Connection state | Description |
|---|---|
| DISCONNECTED | Connection disconnected. The SDK will not automatically reconnect while in this state. This state indicates that the user is in one of the following stages:
|
| CONNECTING | Joining. The instantaneous state after calling join. |
| CONNECTED | Occurs after the app has successfully joined the channel. At this point the user can publish or subscribe to the audio and video in the channel. |
| RECONNECTING | Occurs when the connection is interrupted due to a network disconnection or switch. The SDK automatically tries to reconnect after an interruption. |
| DISCONNECTING | Disconnecting. This is the state when leave is called. |
