From e4af5ddbe9c593bfe6bb1f68876903ff5744bc2a Mon Sep 17 00:00:00 2001 From: paweldomas Date: Tue, 23 Apr 2019 13:37:19 -0500 Subject: [PATCH] feat(base/connection): throw error and add isInviteURLReady --- react/features/base/connection/functions.js | 34 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/react/features/base/connection/functions.js b/react/features/base/connection/functions.js index 7bb040852..900b07b33 100644 --- a/react/features/base/connection/functions.js +++ b/react/features/base/connection/functions.js @@ -3,23 +3,47 @@ import { toState } from '../redux'; /** - * 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. + * 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. * - * @param {Function|Object} stateOrGetState - The redux state or redux's - * {@code getState} function. + * @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function or the URL object + * to be stripped. * @returns {string} */ export function getInviteURL(stateOrGetState: Function | Object): string { const state = toState(stateOrGetState); - const locationURL + let locationURL = state instanceof URL ? state : state['features/base/connection'].locationURL; + // 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'); + } + return getURLWithoutParams(locationURL).href; } +/** + * 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} + */ +export function isInviteURLReady(stateOrGetState: Function | Object): boolean { + const state = toState(stateOrGetState); + + return Boolean(state['features/base/connection'].locationURL || state['features/base/config'].locationURL); +} + /** * Gets a {@link URL} without hash and query/search params from a specific * {@code URL}.