The network detection tool is an SDK plugin from RC. It checks your client’s connection to RC services and provides detailed data reports.
Add it to your test or production app and run detection when needed. This helps RC report quality data, quickly find, and fix issues.
Network detection process
sequenceDiagram
App->>NetworkTester: Initialize plugin
NetworkTester-->>App: Success or failure
App->>NetworkTester: Register callback listener
App->>NetworkTester: Start detection
NetworkTester->>Server: Detecting
NetworkTester-->>App: Callback returns detecting info
App->>NetworkTester: (Optional) Active detection
NetworkTester-->>App: Callback returns final result
NetworkTester->>Server: Report detection result
Prerequisites
- Get the App Key and confirm its data center
- Get the Token, e.g., the current client user’s Token
Add network detection plugin
The plugin supports maven integration.
-
Open
build.gradle
in the root directory (under Project view) and add [RongCloud’s Maven repository].allprojects { repositories { ... // RC maven repository URL maven {url "https://maven.rongcloud.cn/repository/maven-releases/"} } }
-
Add this dependency in your project’s
build.gradle
file:dependencies { ... // Network detection tool implementation 'cn.rongcloud.sdk:network_detector:1.0.0' }
Check network quality
-
Initialize the network detection plugin.
RCNetworkDetector.getInstance().init(mContext, appKey, token, category);
Use these data center enum values for the
category
parameter:public enum RCEnvironmentCategory { BEIJING(1, "BJ"),// Beijing SINGAPORE(2, "singapore"),// Singapore NORTH_AMERICA(3, "north america");// North America }
-
After initialization, register the network detection result listener. During detection, the Navi service address is reported via
onReportNaviResult
, and the CMP service address is reported viaonReportCmpResult
. Most apps only need the final result fromonFinished
.RCNetworkDetector.getInstance().addDetectorListener()
public interface RCNetworkDetectorListener { /** * Network detection starts * * @param sessionId Session ID */ void onStartWith(@NonNull String sessionId); /** * Report Navi detection result * * @param result Navi detection result * @param index Navi index * @param count Navi total * @param error Error message */ void onReportNaviResult( @NonNull RCNaviConnectResult result, int index, int count, @Nullable RCError error); /** * Report CMP detection result * * @param result CMP detection result * @param index CMP index * @param count CMP total * @param error Error message */ void onReportCmpResult( @NonNull RCCMPConnectResult result, int index, int count, @Nullable RCError error); /** * Detection ends * * @param result Detection result * @param error Error message */ void onFinished(@RCConstant.DetectorResult int result, @Nullable RCError error); }
-
Start detection.
RCNetworkDetector.getInstance().start(mWebView);
During detection, the
RCNetworkDetectorListener
methods from the previous step will run to provide results. -
Detection ends automatically when complete.
You can stop detection while it’s running. After stopping, the plugin will return the result via
onFinished
.
RCNetworkDetector.getInstance().stop();
Get network detection data
The plugin also provides these query methods:
// Get device info
RCNetworkDetector.getInstance().getDeviceInfo();
// Get session ID
RCNetworkDetector.getInstance().getSessionId();
// Get navigation detection result
RCNetworkDetector.getInstance().getNaviResults();
// Get CMP detection result
RCNetworkDetector.getInstance().getCMPResult();
Reference
RCNaviConnectResult
Navigation detection result.
// Navigation detection result
public class RCNaviConnectResult {
// navi address
@SerializedName("address")
private String address;
// request status
@SerializedName("status")
private int status;
// total time cost
@SerializedName("cost")
private long cost;
// tcp time cost
@SerializedName("connect")
private long connect;
// dns time cost
@SerializedName("dns")
private long dns;
// system error code
@SerializedName("code")
private int code;
// navi version
@RCConstant.NaviVersion
@SerializedName("version")
private int version;
// remote IP
@SerializedName("remote")
private String remote;
// http status code
@SerializedName("http_code")
private int httpCode;
// system error description
@SerializedName("message")
private String message;
}
RCCMPConnectResult
CMP detection result.
// CMP detection result
public class RCCMPConnectResult {
// detection address
@SerializedName("address")
private String address;
// detection type: HttpTLS, HttpNoneTLS, WebSocketTLS, WebSocketNoneTLS
@RCConstant.CMPType
@SerializedName("type")
private String type;
// detection status: success, failure, timeout
@SerializedName("status")
private int status;
// detection time cost
@SerializedName("cost")
private long cost;
// dns time cost
@SerializedName("dns")
private long dns;
// tcp time cost
@SerializedName("connect")
private long connect;
// business link time cost
@SerializedName("bs")
private long bs;
// TCP error code
@SerializedName("connect_code")
private int connectCode;
// rmtp error code
@SerializedName("rmtp_code")
private int rmtpCode;
// business link result
@SerializedName("rmtp_status")
private int rmtpStatus;
}
RCDeviceInfo
Device info.
// Device info
public class RCDeviceInfo {
// OS
@SerializedName("os")
private String OS;
// OS name
@SerializedName("os_name")
private String OSName;
// OS version
@SerializedName("os_version")
private String OSVersion;
// brand
@SerializedName("os_brand")
private String OSBrand;
// device model
@SerializedName("device_model")
private String DeviceModel;
// network type
@SerializedName("network_type")
private String networkType;
// gateway
@SerializedName("gateway")
private String gateway;
// dns
@SerializedName("dns")
private String DNS;
// carrier
@SerializedName("carrier")
private String carrier;
// proxy
@SerializedName("proxy")
private String proxy;
// signal strength
@SerializedName("signal_strength")
private String signalStrength;
}
Status codes
RCError
defines error codes that may occur during network detection.
Status code | Reason |
---|---|
RC_DETECTOR_RESULT_STOPPED_BY_USER | Actively called the detection stop interface, terminating detection early |
RC_DETECTOR_RESULT_FINISHED | Detection successful (normal detection end) |
RC_DETECTOR_RESULT_NETWORK_EXCEPTION | Detection failed (network exception) |
RC_DETECTOR_RESULT_OTHER | Other exceptions |