Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(base/connection): throw error and add isInviteURLReady

paweldomase4af5ddbe9c5
diff --git a/react/features/base/connection/functions.js b/react/features/base/connection/functions.js
index 7bb0408529..900b07b335 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}.