Skip to content

Commit

Permalink
Fix Inconsistencies with disableVideo/disableAudio (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Santiago Souto <[email protected]>
  • Loading branch information
juanpiquerez and Santiago-Souto authored Nov 5, 2024
1 parent e4e7b8c commit 83384a6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/millicast-viewer-demo/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 83384a6

Please sign in to comment.