Skip to content

Commit

Permalink
bring back upstream changes that got lost with the revert of the 2022…
Browse files Browse the repository at this point in the history
….9.1 merge
  • Loading branch information
csett86 committed Oct 28, 2022
1 parent 2ce1f1c commit 30f46c9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 19 deletions.
10 changes: 2 additions & 8 deletions app/features/conference/components/Conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { push } from 'react-router-redux';
import i18n from '../../../i18n';
import config from '../../config';
import { getSetting } from '../../settings';
import { parseURLParams } from '../../utils/parseURLParams';

import { conferenceEnded, conferenceJoined } from '../actions';
import JitsiMeetExternalAPI from '../external_api';
Expand Down Expand Up @@ -178,14 +179,7 @@ class Conference extends Component<Props, State> {
const roomName = url.pathname.split('/').pop();
const host = this._conference.serverURL.replace(/https?:\/\//, '');
const searchParameters = Object.fromEntries(url.searchParams);
const hashParameters = url.hash.substring(1).split('&')
.reduce((res, item) => {
const parts = item.split('=');

res[parts[0]] = parts[1];

return res;
}, {});
const hashParameters = parseURLParams(url);

const locale = { lng: i18n.language };
const urlParameters = {
Expand Down
2 changes: 1 addition & 1 deletion app/features/conference/external_api.js

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions app/features/utils/parseURLParams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Bourne from '@hapi/bourne';

/**
* Prints the error and reports it to the global error handler.
*
* @param {Error} e - The error object.
* @param {string} msg - A custom message to print in addition to the error.
* @returns {void}
*/
export function reportError(e, msg = '') {
console.error(msg, e);
window.onerror && window.onerror(msg, undefined, undefined, undefined, e);
}


/**
* A list if keys to ignore when parsing.
*
* @type {string[]}
*/
const blacklist = [ '__proto__', 'constructor', 'prototype' ];

/**
* Parses the query/search or fragment/hash parameters out of a specific URL and
* returns them as a JS object.
*
* @param {URL} url - The URL to parse.
* @param {boolean} dontParse - If falsy, some transformations (for parsing the
* value as JSON) will be executed.
* @param {string} source - If {@code 'search'}, the parameters will parsed out
* of {@code url.search}; otherwise, out of {@code url.hash}.
* @returns {Object}
*/
export function parseURLParams(
url,
dontParse = false,
source = 'hash') {
if (typeof url === 'string') {
// eslint-disable-next-line no-param-reassign
url = new URL(url);
}
const paramStr = source === 'search' ? url.search : url.hash;
const params = {};
const paramParts = (paramStr && paramStr.substring(1).split('&')) || [];

// Detect and ignore hash params for hash routers.
if (source === 'hash' && paramParts.length === 1) {
const firstParam = paramParts[0];

if (firstParam.startsWith('/') && firstParam.split('&').length === 1) {
return params;
}
}

paramParts.forEach(part => {
const param = part.split('=');
const key = param[0];

if (!key || key.split('.').some(k => blacklist.includes(k))) {
return;
}

let value;

try {
value = param[1];

if (!dontParse) {
const decoded = decodeURIComponent(value).replace(/\\&/, '&');

value = decoded === 'undefined' ? undefined : Bourne.parse(decoded);
}
} catch (e) {
reportError(
e, `Failed to parse URL parameter value: ${String(value)}`);

return;
}
params[key] = value;
});

return params;
}
2 changes: 1 addition & 1 deletion app/preload/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function setupRenderer(api, options = {}) {

// Allow window to be on top if enabled in settings
if (options.enableAlwaysOnTopWindow) {
setupAlwaysOnTopRender(api);
setupAlwaysOnTopRender(api, null, { showOnPrejoin: true });
}

// Disable WiFiStats on mac due to jitsi-meet-electron#585
Expand Down
21 changes: 12 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,21 @@ function createJitsiMeetWindow() {
enableBlinkFeatures: 'WebAssemblyCSP',
contextIsolation: false,
nodeIntegration: false,
preload: path.resolve(basePath, './build/preload.js')
preload: path.resolve(basePath, './build/preload.js'),
sandbox: false
}
};

const windowOpenHandler = ({ url, frameName }) => {
const target = getPopupTarget(url, frameName);

if (!target || target === 'browser') {
openExternalLink(url);
}

return { action: 'deny' };
};

mainWindow = new BrowserWindow(options);
windowState.manage(mainWindow);
mainWindow.loadURL(indexURL);
Expand Down Expand Up @@ -244,14 +255,6 @@ function createJitsiMeetWindow() {
new RemoteControlMain(mainWindow); // eslint-disable-line no-new
}

mainWindow.webContents.on('new-window', (event, url, frameName) => {
const target = getPopupTarget(url, frameName);

if (!target || target === 'browser') {
event.preventDefault();
openExternalLink(url);
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"@babel/preset-env": "^7.16.11",
"@babel/preset-flow": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@hapi/bourne": "^3.0.0",
"@jitsi/js-utils": "2.0.0",
"@svgr/webpack": "^6.2.1",
"babel-eslint": "10.0.3",
Expand Down

0 comments on commit 30f46c9

Please sign in to comment.