[mirotalksfu] - improve getMicrophoneVolumeIndicator

هذا الالتزام موجود في:
Miroslav Pejic
2023-09-07 16:15:41 +02:00
الأصل 61e9045d08
التزام db6e725489

عرض الملف

@@ -401,6 +401,7 @@ function addChild(device, els) {
// ####################################################
function getMicrophoneVolumeIndicator(stream) {
if (isAudioContextSupported() && hasAudioTrack(stream)) {
stopMicrophoneProcessing();
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const microphone = audioContext.createMediaStreamSource(stream);
@@ -417,6 +418,7 @@ function getMicrophoneVolumeIndicator(stream) {
};
microphone.connect(scriptProcessor);
scriptProcessor.connect(audioContext.destination);
}
}
function stopMicrophoneProcessing() {
@@ -436,6 +438,20 @@ function updateVolumeIndicator(volume) {
});
}
function isAudioContextSupported() {
return !!(window.AudioContext || window.webkitAudioContext);
}
function hasAudioTrack(mediaStream) {
const audioTracks = mediaStream.getAudioTracks();
return audioTracks.length > 0;
}
function hasVideoTrack(mediaStream) {
const videoTracks = mediaStream.getVideoTracks();
return videoTracks.length > 0;
}
// ####################################################
// API CHECK
// ####################################################