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.

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