From 83384a673856b568ab8582429ff76c29cae39792 Mon Sep 17 00:00:00 2001 From: Juan Pablo Piquerez <71521276+juanpiquerez@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:50:32 -0300 Subject: [PATCH] Fix Inconsistencies with disableVideo/disableAudio (#475) Co-authored-by: Santiago Souto --- packages/millicast-viewer-demo/src/viewer.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/millicast-viewer-demo/src/viewer.js b/packages/millicast-viewer-demo/src/viewer.js index 2f0e5ecf..af961c6d 100644 --- a/packages/millicast-viewer-demo/src/viewer.js +++ b/packages/millicast-viewer-demo/src/viewer.js @@ -59,6 +59,8 @@ let video = document.querySelector("video"); // MillicastView object let millicastView = null +let hasVideo = false +let hasAudio = false const newViewer = () => { const tokenGenerator = () => Director.getSubscriber(streamName, accountId, subscriberToken, enableDRM); @@ -80,10 +82,15 @@ const newViewer = () => { } millicastView.configureDRM(drmOptions); } + hasVideo = event.data.tracks.some(track => track.media === 'video') + hasAudio = event.data.tracks.some(track => track.media === 'audio') } }); millicastView.on("track", (event) => { - if (!enableDRM) addStream(event.streams[0]); + if (!enableDRM) { + if(hasVideo && event.track.kind === 'video' || hasAudio && !hasVideo && event.track.kind === 'audio') + addStream(event.streams[0]) + } }); millicastView.on('metadata', (metadata) => { @@ -135,7 +142,7 @@ const addStream = (stream) => { playing = true; const audio = document.querySelector("audio"); - if (disableVideo) { + if (disableVideo || !hasVideo) { if (audio) audio.srcObject = stream; if (video) video.parentNode.removeChild(video); togglePlay();