You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* @flow */
  2. import { toState } from '../redux';
  3. /**
  4. * Retrieves a simplified version of the conference/location URL stripped of URL
  5. * params (i.e. query/search and hash) which should be used for sending invites.
  6. *
  7. * @param {Function|Object} stateOrGetState - The redux state or redux's
  8. * {@code getState} function.
  9. * @returns {string|undefined}
  10. */
  11. export function getInviteURL(stateOrGetState: Function | Object): ?string {
  12. const state = toState(stateOrGetState);
  13. const locationURL
  14. = state instanceof URL
  15. ? state
  16. : state['features/base/connection'].locationURL;
  17. return locationURL ? getURLWithoutParams(locationURL).href : undefined;
  18. }
  19. /**
  20. * Gets a {@link URL} without hash and query/search params from a specific
  21. * {@code URL}.
  22. *
  23. * @param {URL} url - The {@code URL} which may have hash and query/search
  24. * params.
  25. * @returns {URL}
  26. */
  27. export function getURLWithoutParams(url: URL): URL {
  28. const { hash, search } = url;
  29. if ((hash && hash.length > 1) || (search && search.length > 1)) {
  30. url = new URL(url.href); // eslint-disable-line no-param-reassign
  31. url.hash = '';
  32. url.search = '';
  33. // XXX The implementation of URL at least on React Native appends ? and
  34. // # at the end of the href which is not desired.
  35. let { href } = url;
  36. if (href) {
  37. href.endsWith('#') && (href = href.substring(0, href.length - 1));
  38. href.endsWith('?') && (href = href.substring(0, href.length - 1));
  39. // eslint-disable-next-line no-param-reassign
  40. url.href === href || (url = new URL(href));
  41. }
  42. }
  43. return url;
  44. }