-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): make rtc more stable (#937)
* fix(web): listen to track-ended * refactor(web): add hot plug * refactor(web): add check of low volume * refactor(web): adjust low volume value, add more logs * refactor(web): reduce logs & only check local volume
- Loading branch information
Showing
6 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import AgoraRTC, { ICameraVideoTrack } from "agora-rtc-sdk-ng"; | ||
import type { IMicrophoneAudioTrack } from "agora-rtc-sdk-ng"; | ||
|
||
let microphoneTrack: IMicrophoneAudioTrack | undefined; | ||
export function setMicrophoneTrack(track?: IMicrophoneAudioTrack): void { | ||
microphoneTrack = track; | ||
} | ||
|
||
let cameraTrack: ICameraVideoTrack | undefined; | ||
export function setCameraTrack(track?: ICameraVideoTrack): void { | ||
cameraTrack = track; | ||
} | ||
|
||
AgoraRTC.onMicrophoneChanged = async changedDevice => { | ||
if (changedDevice.state === "ACTIVE") { | ||
console.log("[rtc] microphone new device: %s", changedDevice.device.deviceId); | ||
microphoneTrack?.setDevice(changedDevice.device.deviceId); | ||
} else if (changedDevice.device.label === microphoneTrack?.getTrackLabel()) { | ||
console.log("[rtc] microphone pull out"); | ||
const [microphone] = await AgoraRTC.getMicrophones(); | ||
console.log("[rtc] microphone old device: %s", microphone.deviceId); | ||
microphone && microphoneTrack.setDevice(microphone.deviceId); | ||
} | ||
}; | ||
|
||
AgoraRTC.onCameraChanged = async changedDevice => { | ||
if (changedDevice.state === "ACTIVE") { | ||
console.log("[rtc] camera new device: %s", changedDevice.device.deviceId); | ||
cameraTrack?.setDevice(changedDevice.device.deviceId); | ||
} else if (changedDevice.device.label === cameraTrack?.getTrackLabel()) { | ||
console.log("[rtc] camera pull out"); | ||
const [camera] = await AgoraRTC.getMicrophones(); | ||
console.log("[rtc] camera old device: %s", camera.deviceId); | ||
camera && cameraTrack.setDevice(camera.deviceId); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters