Skip to content

Commit 72c2647

Browse files
committed
[wip] feat(screensharing): use setDisplayMediaRequestHandler
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent 306ebcc commit 72c2647

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/preload.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ const TALK_DESKTOP = {
165165
* @return {Promise<void>}
166166
*/
167167
showUpgrade: () => ipcRenderer.invoke('upgrade:show'),
168+
169+
onPromptDesktopCaptureSource: (callback) => ipcRenderer.on('talk:onPromptDesktopCaptureSource', (_event, sources) => callback(sources)),
170+
desktopCaptureSourceSelected: (source) => ipcRenderer.send('talk:desktopCaptureSourceSelected', source),
168171
}
169172

170173
// Set global window.TALK_DESKTOP

src/talk/renderer/AppGetDesktopMediaSource.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { ref } from 'vue'
88
99
import DesktopMediaSourceDialog from './components/DesktopMediaSourceDialog.vue'
1010
11+
const props = defineProps({
12+
sources: {
13+
type: Array,
14+
required: true,
15+
},
16+
})
17+
1118
const showDialog = ref(false)
1219
1320
let promiseWithResolvers = null
@@ -36,5 +43,8 @@ defineExpose({ promptDesktopMediaSource })
3643
</script>
3744

3845
<template>
39-
<DesktopMediaSourceDialog v-if="showDialog" @submit="handlePrompt($event)" @cancel="handlePrompt('')" />
46+
<DesktopMediaSourceDialog v-if="showDialog"
47+
:sources="sources"
48+
@submit="handlePrompt($event)"
49+
@cancel="handlePrompt('')" />
4050
</template>

src/talk/renderer/components/DesktopMediaSourceDialog.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
1616
import { translate as t } from '@nextcloud/l10n'
1717
import DesktopMediaSourcePreview from './DesktopMediaSourcePreview.vue'
1818
19+
const props = defineProps({
20+
sources: {
21+
type: Array,
22+
required: true,
23+
},
24+
})
25+
1926
const emit = defineEmits(['submit', 'cancel'])
2027
2128
const RE_REQUEST_SOURCES_TIMEOUT = 1000
@@ -47,10 +54,10 @@ const dialogButtons = computed(() => [
4754
])
4855
4956
const requestDesktopCapturerSources = async () => {
50-
sources.value = await window.TALK_DESKTOP.getDesktopCapturerSources()
57+
// props.sources = await window.TALK_DESKTOP.getDesktopCapturerSources()
5158
5259
// There is no source. Probably the user hasn't granted the permission.
53-
if (!sources.value) {
60+
if (!props.sources) {
5461
emit('cancel')
5562
}
5663

src/talk/renderer/getDesktopMediaSource.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ let appGetDesktopMediaSourceInstance
1313
/**
1414
* Prompt user to select a desktop media source to share and return the selected sourceId or an empty string if canceled
1515
*
16+
* @param sources
1617
* @return {Promise<{ sourceId: string }>} sourceId of the selected mediaSource or an empty string if canceled
1718
*/
18-
export async function getDesktopMediaSource() {
19+
export async function getDesktopMediaSource(sources) {
1920
if (!appGetDesktopMediaSourceInstance) {
2021
const container = document.body.appendChild(document.createElement('div'))
21-
appGetDesktopMediaSourceInstance = new Vue(AppGetDesktopMediaSource).$mount(container)
22+
const AppGetDesktopMediaSourceCreator = Vue.extend(AppGetDesktopMediaSource)
23+
appGetDesktopMediaSourceInstance = new AppGetDesktopMediaSourceCreator({ propsData: { sources } }).$mount(container)
2224
}
2325

2426
return appGetDesktopMediaSourceInstance.promptDesktopMediaSource()

src/talk/renderer/talk.main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ registerTalkDesktopSettingsSection()
3939
await import('./notifications/notifications.store.js')
4040

4141
subscribeBroadcast('talk:conversation:open', ({ token, directCall }) => openConversation(token, { directCall }))
42+
43+
window.TALK_DESKTOP.onPromptDesktopCaptureSource(async (sources) => {
44+
const { sourceId } = await getDesktopMediaSource(sources)
45+
console.log('Selected sourceId:', sourceId)
46+
window.TALK_DESKTOP.desktopCaptureSourceSelected(sourceId)
47+
})

0 commit comments

Comments
 (0)