aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/discord
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-09-19 00:41:52 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-09-19 00:57:47 +0200
commitc5d2a889d4cb44f995d74051f83628b505383093 (patch)
treeb1bab2b6d7f99ab00b0ca9860079f71472ac79ae /recipes/discord
parentFix images opening in browser instead of in Discord (#712) (diff)
downloadferdium-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')
-rw-r--r--recipes/discord/package.json2
-rw-r--r--recipes/discord/webview.js58
2 files changed, 1 insertions, 59 deletions
diff --git a/recipes/discord/package.json b/recipes/discord/package.json
index c644d66..243e64b 100644
--- a/recipes/discord/package.json
+++ b/recipes/discord/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "discord", 2 "id": "discord",
3 "name": "Discord", 3 "name": "Discord",
4 "version": "1.4.1", 4 "version": "1.4.2",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "serviceURL": "https://discordapp.com/login", 7 "serviceURL": "https://discordapp.com/login",
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
3const _path = _interopRequireDefault(require('path')); 1const _path = _interopRequireDefault(require('path'));
4 2
5function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 3function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 4
7window.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
63module.exports = (Ferdi, settings) => { 5module.exports = (Ferdi, settings) => {
64 const getMessages = function getMessages() { 6 const getMessages = function getMessages() {
65 let count = 0; 7 let count = 0;