@@ -52,7 +52,7 @@ export class VideoTrackConstraints {
5252 // eslint-disable-next-line require-jsdoc
5353 constructor ( source ) {
5454 if ( ! Object . values ( MediaFormatModule . VideoSourceInfo )
55- . some ( ( v ) => v === source ) ) {
55+ . some ( ( v ) => v === source ) ) {
5656 throw new TypeError ( 'Invalid source.' ) ;
5757 }
5858 /**
@@ -94,7 +94,6 @@ export class VideoTrackConstraints {
9494 * @constructor
9595 * @param {?Owt.Base.AudioTrackConstraints } audioConstraints
9696 * @param {?Owt.Base.VideoTrackConstraints } videoConstraints
97- * @param {?string } extensionId The ID of Chrome screen sharing extension.
9897 */
9998export class StreamConstraints {
10099 // eslint-disable-next-line require-jsdoc
@@ -111,19 +110,13 @@ export class StreamConstraints {
111110 * @instance
112111 */
113112 this . video = videoConstraints ;
114- /**
115- * @member {string} extensionId
116- * @memberof Owt.Base.MediaStreamDeviceConstraints
117- * @desc The ID of Chrome Extension for screen sharing.
118- * @instance
119- */
120113 }
121114}
122115
123116// eslint-disable-next-line require-jsdoc
124117function isVideoConstrainsForScreenCast ( constraints ) {
125118 return ( typeof constraints . video === 'object' && constraints . video . source ===
126- MediaFormatModule . VideoSourceInfo . SCREENCAST ) ;
119+ MediaFormatModule . VideoSourceInfo . SCREENCAST ) ;
127120}
128121
129122/**
@@ -170,123 +163,63 @@ export class MediaStreamFactory {
170163 'Cannot capture video from screen cast while capture audio from'
171164 + ' other source.' ) ) ;
172165 }
173- // Screen sharing on Chrome does not work with the latest constraints
174- // format.
175- if ( isVideoConstrainsForScreenCast ( constraints ) && utils . isChrome ( ) ) {
176- if ( ! constraints . extensionId ) {
177- return Promise . reject ( new TypeError (
178- 'Extension ID must be specified for screen sharing on Chrome.' ) ) ;
179- }
180- const desktopCaptureSources = [ 'screen' , 'window' , 'tab' ] ;
181- if ( constraints . audio ) {
182- desktopCaptureSources . push ( 'audio' ) ;
166+
167+ // Check and convert constraints.
168+ if ( ! constraints . audio && ! constraints . video ) {
169+ return Promise . reject ( new TypeError (
170+ 'At least one of audio and video must be requested.' ) ) ;
171+ }
172+ const mediaConstraints = Object . create ( { } ) ;
173+ if ( typeof constraints . audio === 'object' &&
174+ constraints . audio . source === MediaFormatModule . AudioSourceInfo . MIC ) {
175+ mediaConstraints . audio = Object . create ( { } ) ;
176+ if ( utils . isEdge ( ) ) {
177+ mediaConstraints . audio . deviceId = constraints . audio . deviceId ;
178+ } else {
179+ mediaConstraints . audio . deviceId = {
180+ exact : constraints . audio . deviceId ,
181+ } ;
183182 }
184- return new Promise ( ( resolve , reject ) => {
185- chrome . runtime . sendMessage (
186- constraints . extensionId , {
187- getStream : desktopCaptureSources ,
188- } ,
189- function ( response ) {
190- if ( response === undefined ) {
191- return reject ( new Error ( chrome . runtime . lastError . message ) ) ;
192- }
193- if ( constraints . audio && typeof response . options !== 'object' ) {
194- Logger . warning (
195- 'Desktop sharing with audio requires the latest Chrome' +
196- ' extension. Your audio constraints will be ignored.' ) ;
197- }
198- const mediaConstraints = Object . create ( { } ) ;
199- if ( constraints . audio && ( typeof response . options === 'object' ) ) {
200- if ( response . options . canRequestAudioTrack ) {
201- mediaConstraints . audio = {
202- mandatory : {
203- chromeMediaSource : 'desktop' ,
204- chromeMediaSourceId : response . streamId ,
205- } ,
206- } ;
207- } else {
208- Logger . warning (
209- 'Sharing screen with audio was not selected by user.' ) ;
210- }
211- }
212- mediaConstraints . video = Object . create ( { } ) ;
213- mediaConstraints . video . mandatory = Object . create ( { } ) ;
214- mediaConstraints . video . mandatory . chromeMediaSource = 'desktop' ;
215- mediaConstraints . video . mandatory . chromeMediaSourceId =
216- response . streamId ;
217- // Transform new constraint format to the old style. Because
218- // chromeMediaSource only supported in the old style, and mix new
219- // and old style will result type error: "Cannot use both
220- // optional/mandatory and specific or advanced constraints.".
221- if ( constraints . video . resolution ) {
222- mediaConstraints . video . mandatory . maxHeight =
223- mediaConstraints . video . mandatory . minHeight =
224- constraints . video . resolution . height ;
225- mediaConstraints . video . mandatory . maxWidth =
226- mediaConstraints . video . mandatory . minWidth =
227- constraints . video . resolution . width ;
228- }
229- if ( constraints . video . frameRate ) {
230- mediaConstraints . video . mandatory . minFrameRate =
231- constraints . video . frameRate ;
232- mediaConstraints . video . mandatory . maxFrameRate =
233- constraints . video . frameRate ;
234- }
235- resolve ( navigator . mediaDevices . getUserMedia ( mediaConstraints ) ) ;
236- } ) ;
237- } ) ;
238183 } else {
239- if ( ! constraints . audio && ! constraints . video ) {
240- return Promise . reject ( new TypeError (
241- 'At least one of audio and video must be requested.' ) ) ;
184+ mediaConstraints . audio = constraints . audio ;
185+ }
186+ if ( typeof constraints . audio === 'object' &&
187+ constraints . audio . source ===
188+ MediaFormatModule . AudioSourceInfo . SCREENCAST ) {
189+ Logger . warning (
190+ 'Screen sharing with audio is not supported in Firefox.' ) ;
191+ mediaConstraints . audio = false ;
192+ }
193+ if ( typeof constraints . video === 'object' ) {
194+ mediaConstraints . video = Object . create ( { } ) ;
195+ if ( typeof constraints . video . frameRate === 'number' ) {
196+ mediaConstraints . video . frameRate = constraints . video . frameRate ;
242197 }
243- const mediaConstraints = Object . create ( { } ) ;
244- if ( typeof constraints . audio === 'object' &&
245- constraints . audio . source === MediaFormatModule . AudioSourceInfo . MIC ) {
246- mediaConstraints . audio = Object . create ( { } ) ;
247- if ( utils . isEdge ( ) ) {
248- mediaConstraints . audio . deviceId = constraints . audio . deviceId ;
249- } else {
250- mediaConstraints . audio . deviceId = {
251- exact : constraints . audio . deviceId ,
252- } ;
253- }
254- } else {
255- mediaConstraints . audio = constraints . audio ;
198+ if ( constraints . video . resolution &&
199+ constraints . video . resolution . width &&
200+ constraints . video . resolution . height ) {
201+ mediaConstraints . video . width = Object . create ( { } ) ;
202+ mediaConstraints . video . width . exact =
203+ constraints . video . resolution . width ;
204+ mediaConstraints . video . height = Object . create ( { } ) ;
205+ mediaConstraints . video . height . exact =
206+ constraints . video . resolution . height ;
256207 }
257- if ( typeof constraints . audio === 'object' &&
258- constraints . audio . source ===
259- MediaFormatModule . AudioSourceInfo . SCREENCAST ) {
260- Logger . warning (
261- 'Screen sharing with audio is not supported in Firefox.' ) ;
262- mediaConstraints . audio = false ;
208+ if ( typeof constraints . video . deviceId === 'string' ) {
209+ mediaConstraints . video . deviceId = { exact : constraints . video . deviceId } ;
263210 }
264- if ( typeof constraints . video === 'object' ) {
265- mediaConstraints . video = Object . create ( { } ) ;
266- if ( typeof constraints . video . frameRate === 'number' ) {
267- mediaConstraints . video . frameRate = constraints . video . frameRate ;
268- }
269- if ( constraints . video . resolution &&
270- constraints . video . resolution . width &&
271- constraints . video . resolution . height ) {
272- mediaConstraints . video . width = Object . create ( { } ) ;
273- mediaConstraints . video . width . exact =
274- constraints . video . resolution . width ;
275- mediaConstraints . video . height = Object . create ( { } ) ;
276- mediaConstraints . video . height . exact =
277- constraints . video . resolution . height ;
278- }
279- if ( typeof constraints . video . deviceId === 'string' ) {
280- mediaConstraints . video . deviceId = { exact : constraints . video . deviceId } ;
281- }
282- if ( utils . isFirefox ( ) &&
283- constraints . video . source ===
284- MediaFormatModule . VideoSourceInfo . SCREENCAST ) {
285- mediaConstraints . video . mediaSource = 'screen' ;
286- }
287- } else {
288- mediaConstraints . video = constraints . video ;
211+ if ( utils . isFirefox ( ) &&
212+ constraints . video . source ===
213+ MediaFormatModule . VideoSourceInfo . SCREENCAST ) {
214+ mediaConstraints . video . mediaSource = 'screen' ;
289215 }
216+ } else {
217+ mediaConstraints . video = constraints . video ;
218+ }
219+
220+ if ( isVideoConstrainsForScreenCast ( constraints ) ) {
221+ return navigator . mediaDevices . getDisplayMedia ( mediaConstraints ) ;
222+ } else {
290223 return navigator . mediaDevices . getUserMedia ( mediaConstraints ) ;
291224 }
292225 }
0 commit comments