diff --git a/src/injected.ts b/src/injected.ts index 5790b255dc..163a25c762 100644 --- a/src/injected.ts +++ b/src/injected.ts @@ -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') || ''; @@ -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); diff --git a/src/servers/preload/api.ts b/src/servers/preload/api.ts index dc3ccb6008..f78cd616ad 100644 --- a/src/servers/preload/api.ts +++ b/src/servers/preload/api.ts @@ -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'; @@ -44,6 +47,7 @@ export type RocketChatDesktopAPI = { ) => Promise; destroyNotification: (id: unknown) => void; getInternalVideoChatWindowEnabled: () => boolean; + openInternalVideoChatWindow: (url: string, options: undefined) => void; setGitCommitHash: (gitCommitHash: string) => void; setServerAllowedRedirects: (allowedRedirects: string[]) => void; }; @@ -69,6 +73,7 @@ export const RocketChatDesktop: RocketChatDesktopAPI = { createNotification, destroyNotification, getInternalVideoChatWindowEnabled, + openInternalVideoChatWindow, setGitCommitHash, setServerAllowedRedirects, }; diff --git a/src/servers/preload/internalVideoChatWindow.ts b/src/servers/preload/internalVideoChatWindow.ts index 94f438f11b..c272f69107 100644 --- a/src/servers/preload/internalVideoChatWindow.ts +++ b/src/servers/preload/internalVideoChatWindow.ts @@ -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); + } +}; diff --git a/src/ui/main/serverView/index.ts b/src/ui/main/serverView/index.ts index 0bbefb8faa..5028741cb2 100644 --- a/src/ui/main/serverView/index.ts +++ b/src/ui/main/serverView/index.ts @@ -215,10 +215,10 @@ export const attachGuestWebContentsEvents = async (): Promise => { 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'),