Skip to content

Commit

Permalink
Implements getDisplayMedia when available on chrome.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Sep 6, 2018
1 parent 21a7993 commit 05e6ea5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
18 changes: 17 additions & 1 deletion modules/RTC/RTCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ function getSSConstraints(options = {}) {
return constraints;
}

/**
* Generates constraints for screen sharing when using getDisplayMedia.
* The constraints(MediaTrackConstraints) are applied to the resulting track.
*
* @returns {Object} - MediaTrackConstraints constraints.
*/
function getTrackSSConstraints() {
// we used to set height and width in the constraints, but this can lead
// to inconsistencies if the browser is on a lower resolution screen
// and we share a screen with bigger resolution, so they are now not set
return {
frameRate: SS_DEFAULT_FRAME_RATE
};
}

/**
* Sets the availbale devices based on the options we requested and the
* streams we received.
Expand Down Expand Up @@ -866,7 +881,8 @@ class RTCUtils extends Listenable {

screenObtainer.init(
options,
this.getUserMediaWithConstraints.bind(this));
this.getUserMediaWithConstraints.bind(this),
getTrackSSConstraints);

if (this.isDeviceListAvailable()) {
this.enumerateDevices(ds => {
Expand Down
38 changes: 35 additions & 3 deletions modules/RTC/ScreenObtainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ let chromeExtUpdateRequired = false;

let gumFunction = null;

/**
* The function used to obtain track constraints MediaTrackConstraints.
* @type {Function}
*/
let getSSConstraints = null;

/**
* The error returned by chrome when trying to start inline installation from
* popup.
Expand Down Expand Up @@ -104,9 +110,10 @@ const ScreenObtainer = {
desktopSharingChromeDisabled: false,
desktopSharingChromeExtId: null,
desktopSharingFirefoxDisabled: false
}, gum) {
}, gum, constraintsFunc) {
this.options = options;
gumFunction = gum;
getSSConstraints = constraintsFunc;

this.obtainStream = this._createObtainStreamMethod(options);

Expand Down Expand Up @@ -167,11 +174,36 @@ const ScreenObtainer = {
logger.info('Chrome extension not supported until ver 34');

return null;
} else if (navigator.getDisplayMedia
&& !options.desktopSharingChromeDisabled) {
return (ops, onSuccess, onFailure) => {
navigator.getDisplayMedia({ video: true })
.then(stream => {
let applyConstraintsPromise;

if (stream
&& stream.getTracks()
&& stream.getTracks().length > 0) {
applyConstraintsPromise
= stream.getTracks()[0]
.applyConstraints(getSSConstraints());
} else {
applyConstraintsPromise = Promise.resolve();
}

applyConstraintsPromise.then(() =>
onSuccess({
stream,
sourceId: stream.id
}));
})
.catch(() =>
onFailure(new JitsiTrackError(JitsiTrackErrors
.CHROME_EXTENSION_USER_CANCELED)));
};
} else if (options.desktopSharingChromeDisabled
|| options.desktopSharingChromeMethod === false
|| !options.desktopSharingChromeExtId) {

// TODO: desktopSharingChromeMethod is deprecated, remove.
return null;
}

Expand Down

0 comments on commit 05e6ea5

Please sign in to comment.