diff options
author | 2021-09-19 01:19:11 +0200 | |
---|---|---|
committer | 2021-09-19 01:19:11 +0200 | |
commit | 6ec6fef9017ee9d8fc436e48448d47b1fda8a820 (patch) | |
tree | 1839f85efb4e45b441e509d2fc12a28a05877e47 /recipes/discord/webview.js | |
parent | Fix images opening in browser instead of in Discord (#712) (diff) | |
parent | also fix privileged API access for googlemeet (diff) | |
download | ferdium-recipes-6ec6fef9017ee9d8fc436e48448d47b1fda8a820.tar.gz ferdium-recipes-6ec6fef9017ee9d8fc436e48448d47b1fda8a820.tar.zst ferdium-recipes-6ec6fef9017ee9d8fc436e48448d47b1fda8a820.zip |
Merge pull request #713 from kris7t/fix-api-access
fix: privileged API access
Diffstat (limited to 'recipes/discord/webview.js')
-rw-r--r-- | recipes/discord/webview.js | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/recipes/discord/webview.js b/recipes/discord/webview.js index 9c96f9f..3134221 100644 --- a/recipes/discord/webview.js +++ b/recipes/discord/webview.js | |||
@@ -1,65 +1,7 @@ | |||
1 | // TODO: Some/most of this is already present in https://github.com/getferdi/ferdi/blob/develop/src/webview/screenshare.js#L5 | ||
2 | |||
3 | const _path = _interopRequireDefault(require('path')); | 1 | const _path = _interopRequireDefault(require('path')); |
4 | 2 | ||
5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | 3 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
6 | 4 | ||
7 | window.navigator.mediaDevices.getDisplayMedia = () => { | ||
8 | return new Promise(async (resolve, reject) => { | ||
9 | try { | ||
10 | const sources = await Ferdi.desktopCapturer.getSources({ types: ['screen', 'window'] }); | ||
11 | |||
12 | const selectionElem = document.createElement('div'); | ||
13 | selectionElem.classList = 'desktop-capturer-selection'; | ||
14 | selectionElem.innerHTML = ` | ||
15 | <div class="desktop-capturer-selection__scroller"> | ||
16 | <ul class="desktop-capturer-selection__list"> | ||
17 | ${sources.map(({ id, name, thumbnail, display_id, appIcon }) => ` | ||
18 | <li class="desktop-capturer-selection__item"> | ||
19 | <button class="desktop-capturer-selection__btn" data-id="${id}" title="${name}"> | ||
20 | <img class="desktop-capturer-selection__thumbnail" src="${thumbnail.toDataURL()}" /> | ||
21 | <span class="desktop-capturer-selection__name">${name}</span> | ||
22 | </button> | ||
23 | </li> | ||
24 | `).join('')} | ||
25 | </ul> | ||
26 | </div> | ||
27 | `; | ||
28 | document.body.appendChild(selectionElem); | ||
29 | |||
30 | document.querySelectorAll('.desktop-capturer-selection__btn') | ||
31 | .forEach(button => { | ||
32 | button.addEventListener('click', async () => { | ||
33 | try { | ||
34 | const id = button.getAttribute('data-id'); | ||
35 | const source = sources.find(source => source.id === id); | ||
36 | if (!source) { | ||
37 | throw new Error(`Source with id ${id} does not exist`); | ||
38 | } | ||
39 | |||
40 | const stream = await window.navigator.mediaDevices.getUserMedia({ | ||
41 | audio: false, | ||
42 | video: { | ||
43 | mandatory: { | ||
44 | chromeMediaSource: 'desktop', | ||
45 | chromeMediaSourceId: source.id | ||
46 | } | ||
47 | } | ||
48 | }); | ||
49 | resolve(stream); | ||
50 | |||
51 | selectionElem.remove(); | ||
52 | } catch (err) { | ||
53 | reject(err); | ||
54 | } | ||
55 | }); | ||
56 | }); | ||
57 | } catch (err) { | ||
58 | reject(err); | ||
59 | } | ||
60 | }) | ||
61 | } | ||
62 | |||
63 | module.exports = (Ferdi, settings) => { | 5 | module.exports = (Ferdi, settings) => { |
64 | const getMessages = function getMessages() { | 6 | const getMessages = function getMessages() { |
65 | let count = 0; | 7 | let count = 0; |