Skip to content
Prev Previous commit
Next Next commit
Extract functions to stop checking audio and media state
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Sep 25, 2020
commit cfdcddbc39bab160412bb9c2edc8668c7c77840c
16 changes: 11 additions & 5 deletions src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,19 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
})
}

function stopPeerCheckMedia(peer) {
function stopPeerCheckAudioMedia(peer) {
clearInterval(peer.check_audio_interval)
peer.check_audio_interval = null
}

function stopPeerCheckVideoMedia(peer) {
clearInterval(peer.check_video_interval)
peer.check_video_interval = null
}

function stopPeerCheckMedia(peer) {
stopPeerCheckAudioMedia(peer)
stopPeerCheckVideoMedia(peer)
stopSendingNick(peer)
}

Expand All @@ -772,17 +780,15 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
peer.check_video_interval = setInterval(function() {
stream.getVideoTracks().forEach(function(video) {
checkPeerMedia(peer, video, 'video').then(function() {
clearInterval(peer.check_video_interval)
peer.check_video_interval = null
stopPeerCheckVideoMedia(peer)
}).catch(() => {
})
})
}, 1000)
peer.check_audio_interval = setInterval(function() {
stream.getAudioTracks().forEach(function(audio) {
checkPeerMedia(peer, audio, 'audio').then(function() {
clearInterval(peer.check_audio_interval)
peer.check_audio_interval = null
stopPeerCheckAudioMedia(peer)
}).catch(() => {
})
})
Expand Down