Skip to content

Commit 3c53d25

Browse files
authored
Merge pull request #12006 from nextcloud/backport/12003/stable29
[stable29] desktop: add screen sharing support
2 parents be2a6e5 + e02464c commit 3c53d25

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/components/TopBar/TopBarMediaControls.vue

+2-6
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,12 @@ export default {
458458
},
459459

460460
toggleScreenSharingMenu() {
461-
if (IS_DESKTOP) {
462-
alert('Unfortunately, Screen sharing is not supported by Nextcloud Talk Preview')
463-
return
464-
}
465-
466461
if (!this.isScreensharingAllowed) {
467462
return
468463
}
469464

470-
if (!this.model.getWebRtc().capabilities.supportScreenSharing) {
465+
// webrtcsupport considers screen share supported only via HTTPS, even if it is actually supported in the browser/desktop
466+
if (!this.model.getWebRtc().capabilities.supportScreenSharing && !IS_DESKTOP) {
471467
if (window.location.protocol === 'https:') {
472468
showMessage(t('spreed', 'Screen sharing is not supported by your browser.'))
473469
} else {

src/utils/webrtc/simplewebrtc/getscreenmedia.js

+41-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,52 @@ export default function(mode, constraints, cb) {
3434
const callback = hasConstraints ? cb : constraints
3535
let error
3636

37-
if (typeof window === 'undefined' || window.location.protocol === 'http:') {
37+
if (!IS_DESKTOP && (typeof window === 'undefined' || window.location.protocol === 'http:')) {
3838
error = new Error('NavigatorUserMediaError')
3939
error.name = 'HTTPS_REQUIRED'
4040
return callback(error)
4141
}
4242

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) {
4483
navigator.mediaDevices.getDisplayMedia({
4584
video: true,
4685
// Disable default audio optimizations, as they are meant to be used

0 commit comments

Comments
 (0)