Skip to content

Commit 53756cf

Browse files
committed
fix: electron 5 support.
1 parent 67a8a9b commit 53756cf

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ const api = new JitsiMeetExternalAPI(...);
122122
setupPowerMonitorRender(api);
123123
```
124124

125+
### NOTE:
126+
If you are using electron 5 you'll need to add 'disable-site-isolation-trials' switch because of [https://github.com/electron/electron/issues/18214](https://github.com/electron/electron/issues/18214):
127+
```
128+
app.commandLine.appendSwitch('disable-site-isolation-trials')
129+
```
130+
125131
## Example
126132

127133
For examples of installation and usage checkout the [Jitsi Meet Electron](https://github.com/jitsi/jitsi-meet-electron) project.

alwaysontop/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ function onAlwaysOnTopWindow(
6363
skipTaskbar: true,
6464
titleBarStyle: undefined,
6565
frame: false,
66-
show: false
66+
show: false,
67+
webPreferences: {
68+
contextIsolation: false
69+
}
6770
}, getPosition(), getSize())
6871
);
6972

alwaysontop/render.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -228,27 +228,35 @@ class AlwaysOnTop extends EventEmitter {
228228
*/
229229
_onMessageReceived(event, { type, data = {} }) {
230230
if (type === 'event' && data.name === 'new-window') {
231-
this._alwaysOnTopBrowserWindow
232-
= remote.BrowserWindow.fromId(data.id);
231+
this._onNewAlwaysOnTopBrowserWindow(data.id);
233232
}
234233
}
235234

236235
/**
237-
* Creates and opens the always on top window.
236+
* Handles 'new-window' always on top events.
238237
*
238+
* @param {number} windowId - The id of the BrowserWindow instance.
239239
* @returns {void}
240240
*/
241-
_openAlwaysOnTopWindow() {
242-
if (this._alwaysOnTopWindow) {
243-
return;
241+
_onNewAlwaysOnTopBrowserWindow(windowId) {
242+
this._alwaysOnTopBrowserWindow = remote.BrowserWindow.fromId(windowId);
243+
const { webContents } = this._alwaysOnTopBrowserWindow;
244+
// if the window is still loading we may end up loosing the injected content when load finishes. We need to wait
245+
// for the loading to be completed. We are using the browser windows events instead of the DOM window ones because
246+
// it appears they are unreliable (readyState is always completed, most of the events are not fired!!!)
247+
if (webContents.isLoading()) {
248+
webContents.on('did-stop-loading', () => this._setupAlwaysOnTopWindow());
249+
} else {
250+
this._setupAlwaysOnTopWindow();
244251
}
245-
ipcRenderer.on('jitsi-always-on-top', this._onMessageReceived);
246-
this._api.on('largeVideoChanged', this._updateLargeVideoSrc);
252+
}
247253

248-
// Intentionally open about:blank. Otherwise if an origin is set, a
249-
// cross-origin redirect can cause any set global variables to be blown
250-
// away.
251-
this._alwaysOnTopWindow = window.open('', 'AlwaysOnTop');
254+
/**
255+
* Sets all necessary content (HTML, CSS, JS) to the always on top window.
256+
*
257+
* @returns {void}
258+
*/
259+
_setupAlwaysOnTopWindow() {
252260
if (!this._alwaysOnTopWindow) {
253261
return;
254262
}
@@ -304,19 +312,13 @@ class AlwaysOnTop extends EventEmitter {
304312
}
305313
};
306314

307-
// Change the dom of 'about:blank' to display the always on top content.
308-
this._alwaysOnTopWindow.onload = () => {
309-
if (!this._alwaysOnTopWindow) {
310-
return;
311-
}
312-
313315
const cssPath = path.join(__dirname, './alwaysontop.css');
314316
const jsPath = path.join(__dirname, './alwaysontop.js');
315317

316318
// Add the markup for the JS to manipulate and load the CSS.
317319
this._alwaysOnTopWindow.document.body.innerHTML = `
318320
<div id="react"></div>
319-
<video autoplay="" id="video" style="transform: none;"></video>
321+
<video autoplay="" id="video" style="transform: none;" muted></video>
320322
<link rel="stylesheet" href="file://${ cssPath }">
321323
`;
322324

@@ -327,7 +329,24 @@ class AlwaysOnTop extends EventEmitter {
327329

328330
scriptTag.setAttribute('src', `file://${ jsPath }`);
329331
this._alwaysOnTopWindow.document.head.appendChild(scriptTag);
330-
};
332+
}
333+
334+
/**
335+
* Creates and opens the always on top window.
336+
*
337+
* @returns {void}
338+
*/
339+
_openAlwaysOnTopWindow() {
340+
if (this._alwaysOnTopWindow) {
341+
return;
342+
}
343+
ipcRenderer.on('jitsi-always-on-top', this._onMessageReceived);
344+
this._api.on('largeVideoChanged', this._updateLargeVideoSrc);
345+
346+
// Intentionally open about:blank. Otherwise if an origin is set, a
347+
// cross-origin redirect can cause any set global variables to be blown
348+
// away.
349+
this._alwaysOnTopWindow = window.open('', 'AlwaysOnTop');
331350
}
332351

333352
/**
@@ -353,8 +372,7 @@ class AlwaysOnTop extends EventEmitter {
353372
this._alwaysOnTopWindow.close();
354373
}
355374

356-
ipcRenderer.removeListener('jitsi-always-on-top',
357-
this._onMessageReceived);
375+
ipcRenderer.removeListener('jitsi-always-on-top', this._onMessageReceived);
358376
}
359377

360378
//we need to tell the main process to close the BrowserWindow because when

popupsconfig/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ function initPopupsConfiguration(jitsiMeetWindow) {
2828
event.newGuest = new BrowserWindow(Object.assign(options, {
2929
titleBarStyle: undefined,
3030
webPreferences: {
31-
nodeIntegration: false
31+
contextIsolation: false,
32+
nodeIntegration: false,
33+
webviewTag: true
3234
}
3335
}));
3436
}

0 commit comments

Comments
 (0)