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

Added support for getDisplayMedia audio capture #3173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions html/demos/janus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2338,11 +2338,12 @@ var Janus = (function (factory) {
let groups = {};
for(let track of tracks) {
delete track.gumGroup;
if(!track.type || !['audio', 'video'].includes(track.type))
if(!track.type || !['audio', 'video', 'screen'].includes(track.type))
continue;
if(!track.capture || track.capture instanceof MediaStreamTrack)
continue;
let group = track.group ? track.group : 'default';
// Avoid assigning regular default group if it is a screen capture
let group = track.group ? track.group : (track.type === 'screen' ? 'screendefault' : 'default');
if(!groups[group])
groups[group] = {};
if(groups[group][track.type])
Expand All @@ -2353,11 +2354,13 @@ var Janus = (function (factory) {
let keys = Object.keys(groups);
for(let key of keys) {
let group = groups[key];
if(!group.audio || !group.video) {
if(!group.audio || (!group.video && !group.screen)) {
if(group.audio)
delete group.audio.gumGroup;
if(group.video)
delete group.video.gumGroup;
if(group.screen)
delete group.screen.gumGroup;
delete groups[key];
}
}
Expand Down Expand Up @@ -2474,7 +2477,7 @@ var Janus = (function (factory) {
}
if(track.capture) {
if(track.gumGroup && groups[track.gumGroup] && groups[track.gumGroup].stream) {
// We did a getUserMedia before already
// We did a getUserMedia/getDisplayMedia before already
let stream = groups[track.gumGroup].stream;
nt = (track.type === 'audio' ? stream.getAudioTracks()[0] : stream.getVideoTracks()[0]);
delete groups[track.gumGroup].stream;
Expand All @@ -2489,26 +2492,35 @@ var Janus = (function (factory) {
pluginHandle.consentDialog(true);
}
let constraints = Janus.trackConstraints(track), stream = null;
if(track.type === 'audio' || track.type === 'video') {
// Use getUserMedia: check if we need to group audio and video together
if(track.type === 'audio' || track.type === 'video' || track.type === 'screen') {
// Set if getUserMedia should be used or if it should be getDisplayMedia
let captureUserMedia = (track.type !== 'screen');
// Check if we need to group audio and video together
if(track.gumGroup) {
let otherType = (track.type === 'audio' ? 'video' : 'audio');
if(groups[track.gumGroup] && groups[track.gumGroup][otherType]) {
let otherTrack = groups[track.gumGroup][otherType];
if(!otherTrack && otherType === 'video') {
// If the other track is not video, then it is screen and should be a getDisplayMedia capture
otherType = 'screen'
otherTrack = groups[track.gumGroup]['screen'];
captureUserMedia = false;
}
let otherConstraints = Janus.trackConstraints(otherTrack);
constraints[otherType] = otherConstraints[otherType];
}
}
stream = await navigator.mediaDevices.getUserMedia(constraints);
if(captureUserMedia) {
stream = await navigator.mediaDevices.getUserMedia(constraints);
} else {
stream = await navigator.mediaDevices.getDisplayMedia(constraints);
}
if(track.gumGroup && constraints.audio && constraints.video) {
// We just performed a grouped getUserMedia, keep track of the
// stream so that we can immediately assign the track later
groups[track.gumGroup].stream = stream;
delete track.gumGroup;
}
} else {
// Use getDisplayMedia
stream = await navigator.mediaDevices.getDisplayMedia(constraints);
}
nt = (track.type === 'audio' ? stream.getAudioTracks()[0] : stream.getVideoTracks()[0]);
}
Expand Down
Loading