Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] desktop: add screen sharing support #12006

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading