TRTC.isSupported().then(checkResult => {// Not supported, guide the user to use a supported browser(Chrome 56+, Edge 80+, Firefox 56+, Safari 11+).if (!checkResult.result) {}// Not support to publish videoif (!checkResult.detail.isH264EncodeSupported) {}// Not support to subscribe videoif (!checkResult.detail.isH264DecodeSupported) {}});
import { DeviceDetector } from 'trtc-sdk-v5/plugins/device-detector'; const trtc = TRTC.create({ plugins: [DeviceDetector] }); // 1. Test Media Device Only const result = await trtc.startPlugin('DeviceDetector'); // 2. Test Media Device & Network Quality const options = { networkDetect: { sdkAppId, userId, userSig } } const resultWithNetwork = await trtc.startPlugin('DeviceDetector', options);
Name | Type | Attributes | Description |
sdkAppId | number | required | Your sdkAppId |
userId | string | required | The userId for testing uplink network quality. It should be different from downlinkUserId. |
userSig | string | required | |
downlinkUserId | string | optional | The userId for testing downlink network quality. It should be different from userId.Fill in downlinkUserId and downlinkUserSig will perform a downlink network test. |
downlinkUserSig | string | optional | |
roomId | number | optional | Optional. The default value is 8080. The value must be an integer of [1, 4294967294]. |
undefined
.Name | Type | Result |
camera | object | { isSuccess: boolean, device: MediaDeviceInfo} |
microphone | object | { isSuccess: boolean, device: MediaDeviceInfo} |
speaker | object | { isSuccess: boolean, device: MediaDeviceInfo} |
network | object | { isSuccess: boolean, result: { quality: number , rtt: number }} The quality is uplink network quality. When the downlinkUserId and downlinkUserSig passed, the quality is the worse one of the uplink and uplink network quality Network Quality Values 0: The network quality is unknown, indicating that the current TRTC instance has not established a media connection 1: The network quality is excellent 2: The network quality is good 3: The network quality is average 4: The network quality is poor 5: The network quality is extremely poor 6: The network connection has been disconnected. |
const cameraList = await TRTC.getCameraList();const hasCameraDevice = cameraList.length > 0;if (!hasCameraDevice) {// User has not any camera.}
try {// Capture and play camera, not need to publish streamawait trtc.startLocalVideo({ view: 'camera-video-view-id', publish: false });} catch(error) {// Common reasons: NotAllowedError or NotReadableError}
// You can get the cameraId from the camera list you got in fisrt step.if (cameraList[1]) {try {await trtc.updateLocalVideo({ option: { cameraId: cameraList[1].deviceId } });} catch(error) {// Common reasons: NotAllowedError or NotReadableError, same with step 2.}}
await trtc.stopLocalVideo();
const microphoneList = await TRTC.getMicrophoneList();const hasMicrophoneDevice = micList.length > 0;if (!hasMicrophoneDevice) {// User has not any microphone.}
try {// Capture microphoneawait trtc.startLocalAudio({ publish: false });trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {event.result.forEach(({ userId, volume }) => {// When userId is an empty string, it represents the volume of the local microphone.const isMe = userId === '';if (isMe) {// show a volume bar based on the value of volume.}})});trtc.enableAudioVolumeEvaluation(500);} catch(error) {// Common reasons: NotAllowedError or NotReadableError}
// You can get the microphoneId from the microphone list you got in fisrt step.if (microphoneList[1]) {try {await trtc.updateLocalAudio({ option: { microphoneId: microphoneList[1].deviceId } });} catch(error) {// Common reasons: NotAllowedError or NotReadableError, same with step 2.}}
// You need to stop microphone when the testing finished.await trtc.stopLocalAudio();// disable audio-volume eventtrtc.enableAudioVolumeEvaluation(-1);
const speakerList = await TRTC.getSpeakerList();if (speakerList.length === 0) {// User has not speaker.}
<audio id="audio-player" src="xxxxx" controls></audio>
const audioElement = document.getElementById('audio-player');if (speakerList[1]) {audioElement.sinkId = speakerList[1].deviceId;}
Was this page helpful?