Skip to content

Commit

Permalink
fix(external_api) drop legacy constructor arguments
Browse files Browse the repository at this point in the history
The new format (using an options object) was introduced 7 years ago.
It's about time.
  • Loading branch information
saghul committed Jan 14, 2025
1 parent 7c1de52 commit 37856e0
Showing 1 changed file with 10 additions and 82 deletions.
92 changes: 10 additions & 82 deletions modules/API/external/external_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,80 +194,6 @@ function changeParticipantNumber(APIInstance, number) {
APIInstance._numberOfParticipants += number;
}

/**
* Generates the URL for the iframe.
*
* @param {string} domain - The domain name of the server that hosts the
* conference.
* @param {string} [options] - Another optional parameters.
* @param {Object} [options.configOverwrite] - Object containing configuration
* options defined in config.js to be overridden.
* @param {Object} [options.interfaceConfigOverwrite] - Object containing
* configuration options defined in interface_config.js to be overridden.
* @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
* authentication.
* @param {string} [options.lang] - The meeting's default language.
* @param {string} [options.roomName] - The name of the room to join.
* @returns {string} The URL.
*/
function generateURL(domain, options = {}) {
return urlObjectToString({
...options,
url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
});
}

/**
* Parses the arguments passed to the constructor. If the old format is used
* the function translates the arguments to the new format.
*
* @param {Array} args - The arguments to be parsed.
* @returns {Object} JS object with properties.
*/
function parseArguments(args) {
if (!args.length) {
return {};
}

const firstArg = args[0];

switch (typeof firstArg) {
case 'string': // old arguments format
case 'undefined': {
// Not sure which format but we are trying to parse the old
// format because if the new format is used everything will be undefined
// anyway.
const [
roomName,
width,
height,
parentNode,
configOverwrite,
interfaceConfigOverwrite,
jwt,
onload,
lang
] = args;

return {
roomName,
width,
height,
parentNode,
configOverwrite,
interfaceConfigOverwrite,
jwt,
onload,
lang
};
}
case 'object': // new arguments format
return args[0];
default:
throw new Error('Can\'t parse the arguments!');
}
}

/**
* Compute valid values for height and width. If a number is specified it's
* treated as pixel units. If the value is expressed in px, em, pt or
Expand Down Expand Up @@ -336,7 +262,7 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
* @param {string} [options.release] - The key used for specifying release if enabled on the backend.
* @param {string} [options.sandbox] - Sandbox directive for the created iframe, if desired.
*/
constructor(domain, ...args) {
constructor(domain, options = {}) {
super();
const {
roomName = '',
Expand All @@ -345,21 +271,22 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
parentNode = document.body,
configOverwrite = {},
interfaceConfigOverwrite = {},
jwt = undefined,
lang = undefined,
onload = undefined,
jwt,
lang,
onload,
invitees,
iceServers,
devices,
userInfo,
e2eeKey,
release,
sandbox = ''
} = parseArguments(args);
sandbox
} = options;
const localStorageContent = jitsiLocalStorage.getItem('jitsiLocalStorage');

this._parentNode = parentNode;
this._url = generateURL(domain, {

this._url = urlObjectToString({
configOverwrite,
iceServers,
interfaceConfigOverwrite,
Expand All @@ -371,7 +298,8 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
appData: {
localStorageContent
},
release
release,
url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
});

this._createIFrame(height, width, sandbox);
Expand Down

0 comments on commit 37856e0

Please sign in to comment.