diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-09-19 00:41:52 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-09-19 00:57:47 +0200 |
commit | c5d2a889d4cb44f995d74051f83628b505383093 (patch) | |
tree | b1bab2b6d7f99ab00b0ca9860079f71472ac79ae /recipes/discord/webview.js | |
parent | Fix images opening in browser instead of in Discord (#712) (diff) | |
download | ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.tar.gz ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.tar.zst ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.zip |
fix: privileged API access
Privileged browser APIs should be accessed from webview.js via the Ferdi
parameter to the exported function.
If any service is broken (e.g., screen sharing), then most likely we
have to fix recipe.js or screenshare.js
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; |