Skip to content

Commit

Permalink
Merge pull request #12003 from nextcloud/desktop/screen-sharing-support
Browse files Browse the repository at this point in the history
desktop: add screen sharing support
  • Loading branch information
nickvergessen authored Apr 4, 2024
2 parents 3816ee7 + a4f3607 commit fcdc529
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 fcdc529

Please sign in to comment.