-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(talk): add public getDesktopMediaSource for screen sharing
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2024 Grigorii Shartsev <me@shgk.me> | ||
- | ||
- @author Grigorii Shartsev <me@shgk.me> | ||
- | ||
- @license AGPL-3.0-or-later | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
|
||
import DesktopMediaSourceDialog from './components/DesktopMediaSourceDialog.vue' | ||
|
||
const showDialog = ref(false) | ||
|
||
let promiseWithResolvers = null | ||
|
||
const handlePrompt = (sourceId) => { | ||
promiseWithResolvers.resolve({ sourceId }) | ||
promiseWithResolvers = null | ||
showDialog.value = false | ||
} | ||
|
||
/** | ||
* Prompt user to select a desktop media source to share and return the selected sourceId or an empty string if canceled | ||
* | ||
* @return {Promise<{ sourceId: string }>} sourceId of the selected mediaSource or an empty string if canceled | ||
*/ | ||
function promptDesktopMediaSource() { | ||
if (promiseWithResolvers) { | ||
return promiseWithResolvers.promise | ||
} | ||
showDialog.value = true | ||
promiseWithResolvers = Promise.withResolvers() | ||
return promiseWithResolvers.promise | ||
} | ||
|
||
defineExpose({ promptDesktopMediaSource }) | ||
</script> | ||
|
||
<template> | ||
<DesktopMediaSourceDialog v-if="showDialog" @submit="handlePrompt($event)" @cancel="handlePrompt('')" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* @copyright Copyright (c) 2024 Grigorii Shartsev <me@shgk.me> | ||
* | ||
* @author Grigorii Shartsev <me@shgk.me> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Vue from 'vue' | ||
|
||
import AppGetDesktopMediaSource from './AppGetDesktopMediaSource.vue' | ||
|
||
/** @type {import('vue').ComponentPublicInstance<AppGetDesktopMediaSource>} */ | ||
let appGetDesktopMediaSourceInstance | ||
|
||
/** | ||
* Prompt user to select a desktop media source to share and return the selected sourceId or an empty string if canceled | ||
* | ||
* @return {Promise<{ sourceId: string }>} sourceId of the selected mediaSource or an empty string if canceled | ||
*/ | ||
export async function getDesktopMediaSource() { | ||
if (!appGetDesktopMediaSourceInstance) { | ||
const container = document.body.appendChild(document.createElement('div')) | ||
appGetDesktopMediaSourceInstance = new Vue(AppGetDesktopMediaSource).$mount(container) | ||
} | ||
|
||
return appGetDesktopMediaSourceInstance.promptDesktopMediaSource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters