Skip to content

Commit

Permalink
fix: Video calls open again on Electron window (#2495)
Browse files Browse the repository at this point in the history
* fix: Video calls open again on Electron window

* fix url validation
  • Loading branch information
jeanfbrito authored Sep 19, 2022
1 parent 256a195 commit 706fde2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ const start = (): void => {

const open = window.open.bind(window);

function isValidURL(url: string): boolean {
try {
new URL(url);
return true;
} catch (err) {
return false;
}
}

Tracker.autorun(() => {
const serverMainVersion = serverInfo.version.split('.')[0];

// Server version above 5.0.0 will change the way the jitsi integration is handled, now we have video provider as an app
// if the server is above 5.1.1 it will use window.RocketChatDesktop?.openInternalVideoChatWindow to open the video call
if (serverMainVersion < 5) {
const jitsiDomain = settings.get('Jitsi_Domain') || '';

Expand All @@ -66,12 +76,13 @@ const start = (): void => {
);
window.open = (url, name, features = '') => {
if (
typeof url === 'string' &&
url.includes(jitsiDomain) &&
!process.mas &&
window.RocketChatDesktop.getInternalVideoChatWindowEnabled()
window.RocketChatDesktop.getInternalVideoChatWindowEnabled() &&
typeof url === 'string' &&
isValidURL(jitsiDomain) &&
url.includes(jitsiDomain)
) {
return open(url, 'Jitsi Meet', `scrollbars=true,${features}`);
return open(url, 'Video Call', `scrollbars=true,${features}`);
}

return open(url, name, features);
Expand Down
7 changes: 6 additions & 1 deletion src/servers/preload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Server } from '../common';
import { setBadge } from './badge';
import { setFavicon } from './favicon';
import { setGitCommitHash } from './gitCommitHash';
import { getInternalVideoChatWindowEnabled } from './internalVideoChatWindow';
import {
getInternalVideoChatWindowEnabled,
openInternalVideoChatWindow,
} from './internalVideoChatWindow';
import { setServerAllowedRedirects } from './serverAllowedRedirects';
import { setBackground } from './sidebar';
import { setTitle } from './title';
Expand Down Expand Up @@ -44,6 +47,7 @@ export type RocketChatDesktopAPI = {
) => Promise<unknown>;
destroyNotification: (id: unknown) => void;
getInternalVideoChatWindowEnabled: () => boolean;
openInternalVideoChatWindow: (url: string, options: undefined) => void;
setGitCommitHash: (gitCommitHash: string) => void;
setServerAllowedRedirects: (allowedRedirects: string[]) => void;
};
Expand All @@ -69,6 +73,7 @@ export const RocketChatDesktop: RocketChatDesktopAPI = {
createNotification,
destroyNotification,
getInternalVideoChatWindowEnabled,
openInternalVideoChatWindow,
setGitCommitHash,
setServerAllowedRedirects,
};
13 changes: 13 additions & 0 deletions src/servers/preload/internalVideoChatWindow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { shell } from 'electron';

import { select } from '../../store';

export const getInternalVideoChatWindowEnabled = (): boolean =>
select(({ isInternalVideoChatWindowEnabled }) => ({
isInternalVideoChatWindowEnabled,
})).isInternalVideoChatWindowEnabled;

export const openInternalVideoChatWindow = (
url: string,
_options: undefined
): void => {
if (!process.mas && getInternalVideoChatWindowEnabled()) {
window.open(url, 'Video Call', `scrollbars=true`);
} else {
shell.openExternal(url);
}
};
4 changes: 2 additions & 2 deletions src/ui/main/serverView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ export const attachGuestWebContentsEvents = async (): Promise<void> => {
return;
}

const isJitsiMeet = frameName === 'Jitsi Meet';
const isVideoCall = frameName === 'Video Call';

const newWindow = new BrowserWindow({
...(isJitsiMeet
...(isVideoCall
? {
webPreferences: {
preload: path.join(app.getAppPath(), 'app/preload.js'),
Expand Down

0 comments on commit 706fde2

Please sign in to comment.