let uplinkTRTC = null;
let downlinkTRTC = null;
let localStream = null;
let testResult = {
uplinkNetworkQualities: [],
downlinkNetworkQualities: [],
average: {
uplinkNetworkQuality: 0,
downlinkNetworkQuality: 0
}
}
async function testUplinkNetworkQuality() {
uplinkTRTC = TRTC.create();
uplinkTRTC.enterRoom({
roomId: 8080,
sdkAppId: 0,
userId: 'user_uplink_test',
userSig: '',
scene: 'rtc'
})
uplinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {
const { uplinkNetworkQuality } = event;
testResult.uplinkNetworkQualities.push(uplinkNetworkQuality);
});
}
async function testDownlinkNetworkQuality() {
downlinkTRTC = TRTC.create();
downlinkTRTC.enterRoom({
roomId: 8080,
sdkAppId: 0,
userId: 'user_downlink_test',
userSig: '',
scene: 'rtc'
});
downlinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {
const { downlinkNetworkQuality } = event;
testResult.downlinkNetworkQualities.push(downlinkNetworkQuality);
})
}
testUplinkNetworkQuality();
testDownlinkNetworkQuality();
setTimeout(() => {
if (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) {
testResult.average.downlinkNetworkQuality = Math.ceil(
testResult.downlinkNetworkQualities.reduce((value, current) => value + current, 0) / testResult.downlinkNetworkQualities.length
);
}
uplinkTRTC.exitRoom();
downlinkTRTC.exitRoom();
}, 15 * 1000);