NETWORK_QUALITY
event.const trtc = TRTC.create();trtc.on(TRTC.EVENT.NETWORK_QUALITY, event => {console.log(`network-quality, uplinkNetworkQuality:${event.uplinkNetworkQuality}, downlinkNetworkQuality: ${event.downlinkNetworkQuality}`)console.log(`uplink rtt:${event.uplinkRTT} loss:${event.uplinkLoss}`)console.log(`downlink rtt:${event.downlinkRTT} loss:${event.downlinkLoss}`)})
TRTC.create()
to create two TRTCs, referred to as uplinkTRTC and downlinkTRTC.NETWORK_QUALITY
event to detect the uplink network quality.NETWORK_QUALITY
event to detect the downlink network quality.let uplinkTRTC = null; // Used to detect uplink network qualitylet downlinkTRTC = null; // Used to detect downlink network qualitylet localStream = null; // Stream used for testinglet testResult = {// Record uplink network quality datauplinkNetworkQualities: [],// Record downlink network quality datadownlinkNetworkQualities: [],average: {uplinkNetworkQuality: 0,downlinkNetworkQuality: 0}}// 1. Test uplink network qualityasync function testUplinkNetworkQuality() {uplinkTRTC = TRTC.create();uplinkTRTC.enterRoom({roomId: 8080,sdkAppId: 0, // Fill in sdkAppIduserId: 'user_uplink_test',userSig: '', // userSig of uplink_testscene: 'rtc'})uplinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {const { uplinkNetworkQuality } = event;testResult.uplinkNetworkQualities.push(uplinkNetworkQuality);});}// 2. Detect downlink network qualityasync function testDownlinkNetworkQuality() {downlinkTRTC = TRTC.create();downlinkTRTC.enterRoom({roomId: 8080,sdkAppId: 0, // Fill in sdkAppIduserId: 'user_downlink_test',userSig: '', // userSigscene: 'rtc'});downlinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {const { downlinkNetworkQuality } = event;testResult.downlinkNetworkQualities.push(downlinkNetworkQuality);})}// 3. Start detectiontestUplinkNetworkQuality();testDownlinkNetworkQuality();// 4. Stop detection after 15s and calculate the average network qualitysetTimeout(() => {// Calculate the average uplink network qualityif (testResult.uplinkNetworkQualities.length > 0) {testResult.average.uplinkNetworkQuality = Math.ceil(testResult.uplinkNetworkQualities.reduce((value, current) => value + current, 0) / testResult.uplinkNetworkQualities.length);}if (testResult.downlinkNetworkQualities.length > 0) {// Calculate the average downlink network qualitytestResult.average.downlinkNetworkQuality = Math.ceil(testResult.downlinkNetworkQualities.reduce((value, current) => value + current, 0) / testResult.downlinkNetworkQualities.length);}// Detection is over, clean up related states.uplinkTRTC.exitRoom();downlinkTRTC.exitRoom();}, 15 * 1000);
Value | Meaning |
0 | The network condition is unknown, indicating that the current TRTC instance has not established an uplink/downlink connection |
1 | The network condition is excellent |
2 | The network condition is good |
3 | The network condition is average |
4 | The network condition is poor |
5 | The network condition is extremely poor |
6 | The network connection has been disconnected. Note: If the downlink network quality is this value, it means that all downlink connections have been disconnected. |
TRTC.updateLocalVideo()
interface or close the video through the TRTC.stopLocalVideo()
method to reduce uplink bandwidth consumption.
Was this page helpful?