您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 1.7KB

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