Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import { doGetJSON } from '../base/util';
  3. declare var $: Function;
  4. declare var interfaceConfig: Object;
  5. const logger = require('jitsi-meet-logger').getLogger(__filename);
  6. /**
  7. * Sends a GET request to obtain the conference ID necessary for identifying
  8. * which conference to join after diaing the dial-in service.
  9. *
  10. * @param {string} baseUrl - The url for obtaining the conference ID (pin) for
  11. * dialing into a conference.
  12. * @param {string} roomName - The conference name to find the associated
  13. * conference ID.
  14. * @param {string} mucURL - In which MUC the conference exists.
  15. * @returns {Promise} - The promise created by the request.
  16. */
  17. export function getDialInConferenceID(
  18. baseUrl: string,
  19. roomName: string,
  20. mucURL: string): Promise<Object> {
  21. const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
  22. return doGetJSON(conferenceIDURL);
  23. }
  24. /**
  25. * Sends a GET request for phone numbers used to dial into a conference.
  26. *
  27. * @param {string} url - The service that returns confernce dial-in numbers.
  28. * @returns {Promise} - The promise created by the request. The returned numbers
  29. * may be an array of numbers or an object with countries as keys and arrays of
  30. * phone number strings.
  31. */
  32. export function getDialInNumbers(url: string): Promise<*> {
  33. return doGetJSON(url);
  34. }
  35. /**
  36. * Sends a post request to an invite service.
  37. *
  38. * @param {string} inviteServiceUrl - The invite service that generates the
  39. * invitation.
  40. * @param {string} inviteUrl - The url to the conference.
  41. * @param {string} jwt - The jwt token to pass to the search service.
  42. * @param {Immutable.List} inviteItems - The list of the "user" or "room"
  43. * type items to invite.
  44. * @returns {Promise} - The promise created by the request.
  45. */
  46. export function invitePeopleAndChatRooms( // eslint-disable-line max-params
  47. inviteServiceUrl: string,
  48. inviteUrl: string,
  49. jwt: string,
  50. inviteItems: Array<Object>): Promise<void> {
  51. if (!inviteItems || inviteItems.length === 0) {
  52. return Promise.resolve();
  53. }
  54. return new Promise((resolve, reject) => {
  55. $.post(
  56. `${inviteServiceUrl}?token=${jwt}`,
  57. JSON.stringify({
  58. 'invited': inviteItems,
  59. 'url': inviteUrl
  60. }),
  61. resolve,
  62. 'json')
  63. .fail((jqxhr, textStatus, error) => reject(error));
  64. });
  65. }
  66. /**
  67. * Sends an ajax request to a directory service.
  68. *
  69. * @param {string} serviceUrl - The service to query.
  70. * @param {string} jwt - The jwt token to pass to the search service.
  71. * @param {string} text - Text to search.
  72. * @param {Array<string>} queryTypes - Array with the query types that will be
  73. * executed - "conferenceRooms" | "user" | "room".
  74. * @returns {Promise} - The promise created by the request.
  75. */
  76. export function searchDirectory( // eslint-disable-line max-params
  77. serviceUrl: string,
  78. jwt: string,
  79. text: string,
  80. queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
  81. ): Promise<Array<Object>> {
  82. const queryTypesString = JSON.stringify(queryTypes);
  83. return fetch(`${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
  84. queryTypesString}&jwt=${jwt}`)
  85. .then(response => {
  86. const jsonify = response.json();
  87. if (response.ok) {
  88. return jsonify;
  89. }
  90. return jsonify
  91. .then(result => Promise.reject(result));
  92. })
  93. .catch(error => {
  94. logger.error(
  95. 'Error searching directory:', error);
  96. return Promise.reject(error);
  97. });
  98. }
  99. /**
  100. * Sends an ajax request to check if the phone number can be called.
  101. *
  102. * @param {string} dialNumber - The dial number to check for validity.
  103. * @param {string} dialOutAuthUrl - The endpoint to use for checking validity.
  104. * @returns {Promise} - The promise created by the request.
  105. */
  106. export function checkDialNumber(
  107. dialNumber: string, dialOutAuthUrl: string): Promise<Object> {
  108. if (!dialOutAuthUrl) {
  109. // no auth url, let's say it is valid
  110. const response = {
  111. allow: true,
  112. phone: `+${dialNumber}`
  113. };
  114. return Promise.resolve(response);
  115. }
  116. const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
  117. return new Promise((resolve, reject) => {
  118. $.getJSON(fullUrl)
  119. .then(resolve)
  120. .catch(reject);
  121. });
  122. }