@@ -34,13 +34,52 @@ export default function(mode, constraints, cb) {
34
34
const callback = hasConstraints ? cb : constraints
35
35
let error
36
36
37
- if ( typeof window === 'undefined' || window . location . protocol === 'http:' ) {
37
+ if ( ! IS_DESKTOP && ( typeof window === 'undefined' || window . location . protocol === 'http:' ) ) {
38
38
error = new Error ( 'NavigatorUserMediaError' )
39
39
error . name = 'HTTPS_REQUIRED'
40
40
return callback ( error )
41
41
}
42
42
43
- if ( navigator . mediaDevices && navigator . mediaDevices . getDisplayMedia ) {
43
+ if ( IS_DESKTOP ) {
44
+ return window . OCA . Talk . Desktop . getDesktopMediaSource ( )
45
+ . then ( ( { sourceId } ) => {
46
+ if ( ! sourceId ) {
47
+ // User canceled
48
+ const error = new Error ( 'NavigatorUserMediaError' )
49
+ error . name = 'PERMISSION_DENIED'
50
+ throw error
51
+ }
52
+
53
+ // Special case for sharing all the screens with desktop audio in Electron
54
+ // In this case, it must have exactly these constraints
55
+ // "entire-desktop:0:0" is a custom sourceId for this specific case
56
+ const constraints = ( sourceId === 'entire-desktop:0:0' )
57
+ ? {
58
+ audio : {
59
+ mandatory : {
60
+ chromeMediaSource : 'desktop' ,
61
+ } ,
62
+ } ,
63
+ video : {
64
+ mandatory : {
65
+ chromeMediaSource : 'desktop' ,
66
+ } ,
67
+ } ,
68
+ }
69
+ : {
70
+ audio : false ,
71
+ video : {
72
+ mandatory : {
73
+ chromeMediaSource : 'desktop' ,
74
+ chromeMediaSourceId : sourceId ,
75
+ } ,
76
+ } ,
77
+ }
78
+ return navigator . mediaDevices . getUserMedia ( constraints )
79
+ } )
80
+ . then ( ( stream ) => callback ( null , stream ) )
81
+ . catch ( ( error ) => callback ( error ) )
82
+ } else if ( navigator . mediaDevices && navigator . mediaDevices . getDisplayMedia ) {
44
83
navigator . mediaDevices . getDisplayMedia ( {
45
84
video : true ,
46
85
// Disable default audio optimizations, as they are meant to be used
0 commit comments