Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Video calls open again on Electron window #2495

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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