Skip to content

Commit

Permalink
Merge pull request #12006 from nextcloud/backport/12003/stable29
Browse files Browse the repository at this point in the history
[stable29] desktop: add screen sharing support
  • Loading branch information
ShGKme authored Apr 4, 2024
2 parents be2a6e5 + e02464c commit 3c53d25
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/components/TopBar/TopBarMediaControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,12 @@ export default {
},
toggleScreenSharingMenu() {
if (IS_DESKTOP) {
alert('Unfortunately, Screen sharing is not supported by Nextcloud Talk Preview')
return
}
if (!this.isScreensharingAllowed) {
return
}
if (!this.model.getWebRtc().capabilities.supportScreenSharing) {
// webrtcsupport considers screen share supported only via HTTPS, even if it is actually supported in the browser/desktop
if (!this.model.getWebRtc().capabilities.supportScreenSharing && !IS_DESKTOP) {
if (window.location.protocol === 'https:') {
showMessage(t('spreed', 'Screen sharing is not supported by your browser.'))
} else {
Expand Down
43 changes: 41 additions & 2 deletions src/utils/webrtc/simplewebrtc/getscreenmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,52 @@ export default function(mode, constraints, cb) {
const callback = hasConstraints ? cb : constraints
let error

if (typeof window === 'undefined' || window.location.protocol === 'http:') {
if (!IS_DESKTOP && (typeof window === 'undefined' || window.location.protocol === 'http:')) {
error = new Error('NavigatorUserMediaError')
error.name = 'HTTPS_REQUIRED'
return callback(error)
}

if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
if (IS_DESKTOP) {
return window.OCA.Talk.Desktop.getDesktopMediaSource()
.then(({ sourceId }) => {
if (!sourceId) {
// User canceled
const error = new Error('NavigatorUserMediaError')
error.name = 'PERMISSION_DENIED'
throw error
}

// Special case for sharing all the screens with desktop audio in Electron
// In this case, it must have exactly these constraints
// "entire-desktop:0:0" is a custom sourceId for this specific case
const constraints = (sourceId === 'entire-desktop:0:0')
? {
audio: {
mandatory: {
chromeMediaSource: 'desktop',
},
},
video: {
mandatory: {
chromeMediaSource: 'desktop',
},
},
}
: {
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceId,
},
},
}
return navigator.mediaDevices.getUserMedia(constraints)
})
.then((stream) => callback(null, stream))
.catch((error) => callback(error))
} else if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
navigator.mediaDevices.getDisplayMedia({
video: true,
// Disable default audio optimizations, as they are meant to be used
Expand Down

0 comments on commit 3c53d25

Please sign in to comment.