Added support for the new getdisplaymedia API in Chrome 72

master
Håvar Aambø Fosstveit 2019-02-01 13:41:52 +01:00
parent 9b0abb5575
commit 6acd176df1
3 changed files with 59 additions and 32 deletions

View File

@ -134,7 +134,7 @@ export default class RoomClient
device : null
};
this._screenSharing = ScreenShare.create();
this._screenSharing = ScreenShare.create(device);
this._screenSharingProducer = null;

View File

@ -1,5 +1,3 @@
import { getBrowserType } from './utils';
class ChromeScreenShare
{
constructor()
@ -109,6 +107,57 @@ class ChromeScreenShare
}
}
class Chrome72ScreenShare
{
constructor()
{
this._stream = null;
}
start(options = {})
{
const constraints = this._toConstraints(options);
return navigator.mediaDevices.getDisplayMedia(constraints)
.then((stream) =>
{
this._stream = stream;
return Promise.resolve(stream);
});
}
stop()
{
if (this._stream instanceof MediaStream === false)
{
return;
}
this._stream.getTracks().forEach((track) => track.stop());
this._stream = null;
}
isScreenShareAvailable()
{
return true;
}
needExtension()
{
return false;
}
_toConstraints()
{
const constraints = {
video : true
};
return constraints;
}
}
class FirefoxScreenShare
{
constructor()
@ -255,9 +304,9 @@ class DefaultScreenShare
export default class ScreenShare
{
static create()
static create(device)
{
switch (getBrowserType())
switch (device.flag)
{
case 'firefox':
{
@ -265,9 +314,12 @@ export default class ScreenShare
}
case 'chrome':
{
return new ChromeScreenShare();
if (device.version < 72.0)
return new ChromeScreenShare();
else
return new Chrome72ScreenShare();
}
case 'edge':
case 'msedge':
{
return new EdgeScreenShare();
}

View File

@ -19,31 +19,6 @@ export function isMobile()
return !mediaQueryDetectorElem.offsetParent;
}
export function getBrowserType()
{
const ua = navigator.userAgent.toLowerCase();
// Firefox
if (ua.indexOf('firefox') !== -1)
{
return 'firefox';
}
// Chrome
if (ua.indexOf('chrome') !== -1 && ua.indexOf('edge') === -1)
{
return 'chrome';
}
// MSEdge
if (ua.indexOf('edge') !== -1)
{
return 'edge';
}
return 'N/A';
}
/**
* Create a function which will call the callback function
* after the given amount of milliseconds has passed since