Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show the same stream in multiple video elements or multiple div #37

Open
rahul7827 opened this issue Apr 10, 2021 · 0 comments
Open

Comments

@rahul7827
Copy link

this.connection.socketURL = socket_url.length > 0 ? socket_url[0].value : '';

this.connection.socketMessageEvent = 'video-broadcast-demo';

this.connection.session = {
audio: true,
video: true,
oneway: this.isPrivate == 1? false : true
};

this.connection.sdpConstraints.mandatory = {
OfferToReceiveAudio: false,
OfferToReceiveVideo: false
};

this.connection.videosContainer = document.getElementById('videos-container');

let recordAudio, recordVideo;

this.connection.onstream = function(event) {

const existing = document.getElementById(event.streamid);
if (existing && existing.parentNode) {
existing.parentNode.removeChild(existing);
}

event.mediaElement.removeAttribute('src');
event.mediaElement.removeAttribute('srcObject');
event.mediaElement.muted = true;
event.mediaElement.volume = 0;

const video = document.createElement('video');
// const sidecam = document.createElement('video');

try {
video.setAttributeNode(document.createAttribute('autoplay'));
video.setAttributeNode(document.createAttribute('playsinline'));
} catch (e) {
video.setAttribute('autoplay', this.video_attribute);
video.setAttribute('playsinline', this.video_attribute);
}

if (event.type === 'local') {
video.volume = 0;
try {
video.setAttributeNode(document.createAttribute('muted'));
} catch (e) {
video.setAttribute('muted', this.video_attribute);
}
}
video.srcObject = event.stream;
this.camstream_id = event.streamid;

const mediaElement = getHTMLMediaElement(video, {
title: event.userid,
buttons: [],
width: '100%',
showOnMouseEnter: false
});

Array.from(document.getElementById("videos-container").childNodes).forEach((node, index) => {
if(index == 0 || index == 1){console.log(index,'index')}
else{
document.getElementById("videos-container").removeChild(node);
console.log('removing', node);
}
});

document.getElementById('videos-container').appendChild(mediaElement);

//document.getElementById('sidecam').appendChild(mediaElement);

// When i try above line, the first video gets blank, at a time only one video play.

setTimeout(() => {
mediaElement.media.play();

this.capture();

}, 5000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant