diff options
Diffstat (limited to 'recipes/discord')
-rw-r--r-- | recipes/discord/package.json | 2 | ||||
-rw-r--r-- | recipes/discord/webview.js | 58 |
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 | |||
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; |