feat(base/connection): throw error and add isInviteURLReady
This commit is contained in:
parent
768cff48a4
commit
e4af5ddbe9
|
@ -3,23 +3,47 @@
|
||||||
import { toState } from '../redux';
|
import { toState } from '../redux';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a simplified version of the conference/location URL stripped of URL
|
* Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)
|
||||||
* params (i.e. Query/search and hash) which should be used for sending invites.
|
* 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
|
* @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function or the URL object
|
||||||
* {@code getState} function.
|
* to be stripped.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function getInviteURL(stateOrGetState: Function | Object): string {
|
export function getInviteURL(stateOrGetState: Function | Object): string {
|
||||||
const state = toState(stateOrGetState);
|
const state = toState(stateOrGetState);
|
||||||
const locationURL
|
let locationURL
|
||||||
= state instanceof URL
|
= state instanceof URL
|
||||||
? state
|
? state
|
||||||
: state['features/base/connection'].locationURL;
|
: 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;
|
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
|
* Gets a {@link URL} without hash and query/search params from a specific
|
||||||
* {@code URL}.
|
* {@code URL}.
|
||||||
|
|
Loading…
Reference in New Issue