All Products
Search
Document Center

ApsaraVideo Live:Channel connection status management

Last Updated:Nov 10, 2025

This topic helps you understand various channel connection statuses, reasons for status changes, and recommended actions.

Feature introduction

In real-time audio and video scenarios, the connection status between the client and server changes as users join or leave channels. Connection status may also change due to network issues that cause reconnection or disconnection. Therefore, effective management of channel connection status is crucial. It directly affects the user's real-time audio and video experience and involves the stability and reliability of the entire application.

How it works

Connection status

When the connection status changes, the ARTC SDK triggers the onConnectionStatusChange callback. The following figure shows various connection statuses and how they change when users join and leave channels.

image

Automatic reconnection

During a call, if the connection is lost due to network issues, the SDK automatically attempts to reconnect. The following figure shows the callbacks received by User A and User B in the following process: User B is already in the channel, User A joins the channel, experiences network issues, automatically reconnects, and fails to reconnect.

image
  • At T0: User A initiates a joinChannel request.

  • At T1: User A successfully joins the channel and receives the onJoinChannelResult(result=0) and onConnectionStatusChange callbacks.

  • At T2: User B detects that User A has joined the channel and receives the onRemoteUserOnLineNotify callback.

  • At T3: User A's connection is lost due to client network disconnection or other reasons.

  • At T4: User A's SDK detects the network disconnection or does not receive any data from the server for a period of time, initiates automatic reconnection, and User A receives the onConnectionStatusChange callback.

  • At T5: After multiple retry attempts within 100 seconds, the SDK still cannot rejoin the channel and stops trying. It sends the onConnectionStatusChange callback to User A. At this point, the user needs to leave the current channel, check the local network, and rejoin the channel after the network returns to normal.

Sample code

Android

onConnectionStatusChange - Network connection status change callback

@Override
public void onConnectionStatusChange(AliRtcEngine.AliRtcConnectionStatus status, AliRtcEngine.AliRtcConnectionStatusChangeReason reason) {
    super.onConnectionStatusChange(status, reason);
    Log.e(TAG, "onConnectionStatusChange.");
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mLogView != null) {
                mLogView.logI("Network connection changed to: " + status + ", reason: " + reason);
            }
        }
    });
}

IOS

onConnectionStatusChange - Network connection status change callback

/**
 * @brief Channel connection status change callback
 * @param status Current status value, refer to AliRtcConnectionStatus enumeration for corresponding values
 * @param reason Specific reason for the status change, refer to AliRtcConnectionStatusChangeReason enumeration for corresponding values
*/
- (void)onConnectionStatusChange:(AliRtcConnectionStatus)status reason:(AliRtcConnectionStatusChangeReason)reason{
    NSString *stateStr = [NSString stringWithFormat:@"\nNetwork status: %@ status: %ld  Reason: %@ reason: %ld\n",[self callbackNetstatus:status], (long)status,[self callbackNetstatusReason:reason], (long)reason];
    MyLog(@"%@", stateStr);
}

Windows

OnConnectionStatusChange - Network connection status change callback

void AliSDKEventListener::OnConnectionStatusChange(int status, int reason)
{
    if (win_rtc_listener_)
    {
        win_rtc_listener_->OnConnectionStatusChange(status, reason);
    }
}

Status description

Connection status

Connection status

Description

Init

Initial status, occurs before calling joinChannel.

Connecting

Momentary status after calling the joinChannel method.

Connected

Occurs after the app successfully joins the channel.

The SDK also triggers the onJoinChannelResult callback to report that the local client has joined the channel. At this point, the SDK automatically publishes or subscribes to audio and video in the channel, and users can also manually control publishing and subscribing.

Disconnected

Occurs after calling leaveChannel.

Reconnecting

Occurs when the connection is interrupted. The SDK automatically attempts to reconnect after the interruption.

If rejoining the channel is successful, the SDK triggers onConnectionStatusChange

(AliRtcConnectionStatusConnected, AliRtcConnectionChangedSignalingJoinChannelSuccess)

Failed

Connection failed. Occurs when the SDK cannot join the channel within 100 seconds and stops attempting to reconnect. At this point, the user needs to call leaveChannel, check the local network, and call joinChannel again after the network returns to normal.

Status reason description

Connection status (status)

Status reason description (reason)

Init

No reason, initial status.

Connecting

Connecting: Joining the channel.

Connected

JoinChannelSuccess: Successfully joined the channel.

Disconnected

LeaveRoom: User actively left the channel.

Reconnecting

  • HeartbeatTimeout: No data received from the server for a period of time. Possible reasons include downstream network issues or high packet loss.

  • NetworkInterrupted: Client network disconnection.

Failed

JoinChannelFailure: Failed to join or rejoin the channel. Possible reasons include persistent network disconnection or invalid token.