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.

functions.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. declare var $: Function;
  2. declare var interfaceConfig: Object;
  3. /**
  4. * Sends an ajax request to a directory service.
  5. *
  6. * @param {string} serviceUrl - The service to query.
  7. * @param {string} jwt - The jwt token to pass to the search service.
  8. * @param {string} text - Text to search.
  9. * @param {Array<string>} queryTypes - Array with the query types that will be
  10. * executed - "conferenceRooms" | "user" | "room".
  11. * @returns {Promise} - The promise created by the request.
  12. */
  13. export function searchPeople( // eslint-disable-line max-params
  14. serviceUrl,
  15. jwt,
  16. text,
  17. queryTypes = [ 'conferenceRooms', 'user', 'room' ]) {
  18. const queryTypesString = JSON.stringify(queryTypes);
  19. return new Promise((resolve, reject) => {
  20. $.getJSON(`${serviceUrl}?query=${encodeURIComponent(text)}`
  21. + `&queryTypes=${queryTypesString}&jwt=${jwt}`,
  22. response => resolve(response)
  23. ).fail((jqxhr, textStatus, error) =>
  24. reject(error)
  25. );
  26. });
  27. }
  28. /**
  29. * Sends a post request to an invite service.
  30. *
  31. * @param {string} inviteServiceUrl - The invite service that generates the
  32. * invitation.
  33. * @param {string} inviteUrl - The url to the conference.
  34. * @param {string} jwt - The jwt token to pass to the search service.
  35. * @param {Immutable.List} people - The list of the "user" type items to invite.
  36. * @returns {Promise} - The promise created by the request.
  37. */
  38. export function invitePeople(inviteServiceUrl, inviteUrl, jwt, people) { // eslint-disable-line max-params, max-len
  39. return new Promise((resolve, reject) => {
  40. $.post(`${inviteServiceUrl}?token=${jwt}`,
  41. JSON.stringify({
  42. 'invited': people,
  43. 'url': inviteUrl }),
  44. response => resolve(response),
  45. 'json')
  46. .fail((jqxhr, textStatus, error) =>
  47. reject(error)
  48. );
  49. });
  50. }
  51. /**
  52. * Invites room participants to the conference through the SIP Jibri service.
  53. *
  54. * @param {JitsiMeetConference} conference - The conference to which the rooms
  55. * will be invited to.
  56. * @param {Immutable.List} rooms - The list of the "videosipgw" type items to
  57. * invite.
  58. * @returns {void}
  59. */
  60. export function inviteRooms(conference, rooms) {
  61. for (const room of rooms) {
  62. const sipAddress = room.id;
  63. const displayName = room.name;
  64. if (sipAddress && displayName) {
  65. const newSession
  66. = conference.createVideoSIPGWSession(sipAddress, displayName);
  67. newSession.start();
  68. } else {
  69. console.error(
  70. `No display name or sip number for ${JSON.stringify(room)}`);
  71. }
  72. }
  73. }
  74. /**
  75. * Indicates if an invite option is enabled in the configuration.
  76. *
  77. * @param {string} name - The name of the option defined in
  78. * interfaceConfig.INVITE_OPTIONS.
  79. * @returns {boolean} - True to indicate that the given invite option is
  80. * enabled, false - otherwise.
  81. */
  82. export function isInviteOptionEnabled(name) {
  83. return interfaceConfig.INVITE_OPTIONS.indexOf(name) !== -1;
  84. }
  85. /**
  86. * Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
  87. * list.
  88. *
  89. * @param {string} optionName - The invite option name.
  90. * @private
  91. * @returns {number} - The position of the option in the list.
  92. */
  93. export function getInviteOptionPosition(optionName) {
  94. return interfaceConfig.INVITE_OPTIONS.indexOf(optionName);
  95. }