Skip to content

Commit

Permalink
feat(desktop): add screen sharing support
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Apr 4, 2024
1 parent f64ce9c commit ff633a8
Show file tree
Hide file tree
Showing 2 changed files with 26 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 consider screen shared supported only via HTTPS event if it is 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
26 changes: 24 additions & 2 deletions src/utils/webrtc/simplewebrtc/getscreenmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,35 @@ 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
}

return navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceId,
}
}
})
})
.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 ff633a8

Please sign in to comment.