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.

_utils.js 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @flow
  2. /**
  3. * Utility class with no dependencies. Used in components that are stripped in separate bundles
  4. * and requires as less dependencies as possible.
  5. */
  6. import { getURLWithoutParams } from '../base/connection/utils';
  7. import { doGetJSON } from '../base/util';
  8. /**
  9. * Formats the conference pin in readable way for UI to display it.
  10. * Formats the pin in 3 groups of digits:
  11. * XXXX XXXX XX or XXXXX XXXXX XXX.
  12. * The length of first and second group is Math.ceil(pin.length / 3).
  13. *
  14. * @param {Object} conferenceID - The conference id to format, string or number.
  15. * @returns {string} - The formatted conference pin.
  16. * @private
  17. */
  18. export function _formatConferenceIDPin(conferenceID: Object) {
  19. const conferenceIDStr = conferenceID.toString();
  20. // let's split the conferenceID in 3 parts, to be easier to read
  21. const partLen = Math.ceil(conferenceIDStr.length / 3);
  22. return `${
  23. conferenceIDStr.substring(0, partLen)} ${
  24. conferenceIDStr.substring(partLen, 2 * partLen)} ${
  25. conferenceIDStr.substring(2 * partLen, conferenceIDStr.length)}`;
  26. }
  27. /**
  28. * Sends a GET request to obtain the conference ID necessary for identifying
  29. * which conference to join after dialing the dial-in service.
  30. * This function is used not only in the main app bundle but in separate bundles for the dial in numbers page,
  31. * and we do want to limit the dependencies.
  32. *
  33. * @param {string} baseUrl - The url for obtaining the conference ID (pin) for
  34. * dialing into a conference.
  35. * @param {string} roomName - The conference name to find the associated
  36. * conference ID.
  37. * @param {string} mucURL - In which MUC the conference exists.
  38. * @param {URL} url - The address we are loaded in.
  39. * @returns {Promise} - The promise created by the request.
  40. */
  41. export function getDialInConferenceID(
  42. baseUrl: string,
  43. roomName: string,
  44. mucURL: string,
  45. url: URL
  46. ): Promise<Object> {
  47. const separator = baseUrl.includes('?') ? '&' : '?';
  48. const conferenceIDURL
  49. = `${baseUrl}${separator}conference=${roomName}@${mucURL}&url=${getURLWithoutParams(url).href}`;
  50. return doGetJSON(conferenceIDURL, true);
  51. }
  52. /**
  53. * Sends a GET request for phone numbers used to dial into a conference.
  54. * This function is used not only in the main app bundle but in separate bundles for the dial in numbers page,
  55. * and we do want to limit the dependencies.
  56. *
  57. * @param {string} url - The service that returns conference dial-in numbers.
  58. * @param {string} roomName - The conference name to find the associated
  59. * conference ID.
  60. * @param {string} mucURL - In which MUC the conference exists.
  61. * @returns {Promise} - The promise created by the request. The returned numbers
  62. * may be an array of Objects containing numbers, with keys countryCode,
  63. * tollFree, formattedNumber or an object with countries as keys and arrays of
  64. * phone number strings, as the second one should not be used and is deprecated.
  65. */
  66. export function getDialInNumbers(
  67. url: string,
  68. roomName: string,
  69. mucURL: string
  70. ): Promise<*> {
  71. const separator = url.includes('?') ? '&' : '?';
  72. // when roomName and mucURL are available
  73. // provide conference when looking up dial in numbers
  74. return doGetJSON(url + (roomName && mucURL ? `${separator}conference=${roomName}@${mucURL}` : ''), true);
  75. }