aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/discord/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/discord/webview.js')
-rw-r--r--recipes/discord/webview.js58
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
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;