2022-09-14 07:54:56 +00:00
|
|
|
import { IStateful } from '../app/types';
|
|
|
|
import { toState } from '../redux/functions';
|
|
|
|
import { toURLString } from '../util/uri';
|
2019-07-25 10:43:29 +00:00
|
|
|
|
2022-02-28 20:03:42 +00:00
|
|
|
import { getURLWithoutParams } from './utils';
|
|
|
|
|
2019-07-25 10:43:29 +00:00
|
|
|
/**
|
|
|
|
* Figures out what's the current conference URL which is supposed to indicate what conference is currently active.
|
|
|
|
* When not currently in any conference and not trying to join any then 'undefined' is returned.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
|
|
|
|
* @returns {string|undefined}
|
|
|
|
* @private
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function getCurrentConferenceUrl(stateful: IStateful) {
|
2019-07-25 10:43:29 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
let currentUrl;
|
|
|
|
|
|
|
|
if (isInviteURLReady(state)) {
|
|
|
|
currentUrl = toURLString(getInviteURL(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the URL doesn't end with a slash
|
|
|
|
if (currentUrl && currentUrl.substr(-1) === '/') {
|
|
|
|
currentUrl = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentUrl ? currentUrl : undefined;
|
|
|
|
}
|
2017-09-01 21:25:48 +00:00
|
|
|
|
2017-05-31 05:32:13 +00:00
|
|
|
/**
|
2019-04-23 18:37:19 +00:00
|
|
|
* Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)
|
|
|
|
* which should be used for sending invites.
|
|
|
|
* NOTE that the method will throw an error if called too early. That is before the conference is joined or before
|
|
|
|
* the process of joining one has started. This limitation does not apply to the case when called with the URL object
|
|
|
|
* instance. Use {@link isInviteURLReady} to check if it's safe to call the method already.
|
2017-05-31 05:32:13 +00:00
|
|
|
*
|
2019-04-23 18:37:19 +00:00
|
|
|
* @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function or the URL object
|
|
|
|
* to be stripped.
|
2019-04-08 13:10:31 +00:00
|
|
|
* @returns {string}
|
2017-05-31 05:32:13 +00:00
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function getInviteURL(stateOrGetState: IStateful): string {
|
2017-09-01 21:25:48 +00:00
|
|
|
const state = toState(stateOrGetState);
|
2019-04-23 18:37:19 +00:00
|
|
|
let locationURL
|
2017-08-01 00:40:55 +00:00
|
|
|
= state instanceof URL
|
|
|
|
? state
|
|
|
|
: state['features/base/connection'].locationURL;
|
2017-05-31 05:32:13 +00:00
|
|
|
|
2019-04-23 18:37:19 +00:00
|
|
|
// If there's no locationURL on the base/connection feature try the base/config where it's set earlier.
|
|
|
|
if (!locationURL) {
|
|
|
|
locationURL = state['features/base/config'].locationURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!locationURL) {
|
|
|
|
throw new Error('Can not get invite URL - the app is not ready');
|
|
|
|
}
|
|
|
|
|
2020-08-20 07:25:12 +00:00
|
|
|
const { inviteDomain } = state['features/dynamic-branding'];
|
|
|
|
const urlWithoutParams = getURLWithoutParams(locationURL);
|
|
|
|
|
|
|
|
if (inviteDomain) {
|
|
|
|
const meetingId
|
2020-11-16 09:01:31 +00:00
|
|
|
= state['features/base/config'].brandingRoomAlias || urlWithoutParams.pathname.replace(/\//, '');
|
2020-08-20 07:25:12 +00:00
|
|
|
|
|
|
|
return `${inviteDomain}/${meetingId}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return urlWithoutParams.href;
|
2017-05-31 05:32:13 +00:00
|
|
|
}
|
2017-06-01 18:43:57 +00:00
|
|
|
|
2019-04-23 18:37:19 +00:00
|
|
|
/**
|
|
|
|
* Checks whether or not is safe to call the {@link getInviteURL} method already.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function isInviteURLReady(stateOrGetState: IStateful): boolean {
|
2019-04-23 18:37:19 +00:00
|
|
|
const state = toState(stateOrGetState);
|
|
|
|
|
|
|
|
return Boolean(state['features/base/connection'].locationURL || state['features/base/config'].locationURL);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Converts a specific id to jid if it's not jid yet.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
|
|
|
* @param {string} id - User id or jid.
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Object} configHosts - The {@code hosts} part of the {@code config}
|
2017-09-18 07:09:43 +00:00
|
|
|
* object.
|
|
|
|
* @returns {string} A string in the form of a JID (i.e.
|
2017-10-01 06:35:19 +00:00
|
|
|
* {@code user@server.com}).
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function toJid(id: string, { authdomain, domain }: { authdomain?: string; domain?: string; }): string {
|
2017-09-18 07:09:43 +00:00
|
|
|
return id.indexOf('@') >= 0 ? id : `${id}@${authdomain || domain}`;
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|