您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 3.5KB

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