Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.js 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* @flow */
  2. import { toState } from '../redux';
  3. import { toURLString } from '../util';
  4. import { getURLWithoutParams } from './utils';
  5. /**
  6. * Figures out what's the current conference URL which is supposed to indicate what conference is currently active.
  7. * When not currently in any conference and not trying to join any then 'undefined' is returned.
  8. *
  9. * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
  10. * @returns {string|undefined}
  11. * @private
  12. */
  13. export function getCurrentConferenceUrl(stateful: Function | Object) {
  14. const state = toState(stateful);
  15. let currentUrl;
  16. if (isInviteURLReady(state)) {
  17. currentUrl = toURLString(getInviteURL(state));
  18. }
  19. // Check if the URL doesn't end with a slash
  20. if (currentUrl && currentUrl.substr(-1) === '/') {
  21. currentUrl = undefined;
  22. }
  23. return currentUrl ? currentUrl : undefined;
  24. }
  25. /**
  26. * Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)
  27. * which should be used for sending invites.
  28. * NOTE that the method will throw an error if called too early. That is before the conference is joined or before
  29. * the process of joining one has started. This limitation does not apply to the case when called with the URL object
  30. * instance. Use {@link isInviteURLReady} to check if it's safe to call the method already.
  31. *
  32. * @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function or the URL object
  33. * to be stripped.
  34. * @returns {string}
  35. */
  36. export function getInviteURL(stateOrGetState: Function | Object): string {
  37. const state = toState(stateOrGetState);
  38. let locationURL
  39. = state instanceof URL
  40. ? state
  41. : state['features/base/connection'].locationURL;
  42. // If there's no locationURL on the base/connection feature try the base/config where it's set earlier.
  43. if (!locationURL) {
  44. locationURL = state['features/base/config'].locationURL;
  45. }
  46. if (!locationURL) {
  47. throw new Error('Can not get invite URL - the app is not ready');
  48. }
  49. const { inviteDomain } = state['features/dynamic-branding'];
  50. const urlWithoutParams = getURLWithoutParams(locationURL);
  51. if (inviteDomain) {
  52. const meetingId
  53. = state['features/base/config'].brandingRoomAlias || urlWithoutParams.pathname.replace(/\//, '');
  54. return `${inviteDomain}/${meetingId}`;
  55. }
  56. return urlWithoutParams.href;
  57. }
  58. /**
  59. * Checks whether or not is safe to call the {@link getInviteURL} method already.
  60. *
  61. * @param {Function|Object} stateOrGetState - The redux state or redux's {@code getState} function.
  62. * @returns {boolean}
  63. */
  64. export function isInviteURLReady(stateOrGetState: Function | Object): boolean {
  65. const state = toState(stateOrGetState);
  66. return Boolean(state['features/base/connection'].locationURL || state['features/base/config'].locationURL);
  67. }
  68. /**
  69. * Converts a specific id to jid if it's not jid yet.
  70. *
  71. * @param {string} id - User id or jid.
  72. * @param {Object} configHosts - The {@code hosts} part of the {@code config}
  73. * object.
  74. * @returns {string} A string in the form of a JID (i.e.
  75. * {@code user@server.com}).
  76. */
  77. export function toJid(id: string, { authdomain, domain }: Object): string {
  78. return id.indexOf('@') >= 0 ? id : `${id}@${authdomain || domain}`;
  79. }