Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // @flow
  2. import { getInviteURL } from '../base/connection';
  3. import { inviteVideoRooms } from '../videosipgw';
  4. import {
  5. BEGIN_ADD_PEOPLE,
  6. UPDATE_DIAL_IN_NUMBERS_FAILED,
  7. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  8. } from './actionTypes';
  9. import {
  10. getDialInConferenceID,
  11. getDialInNumbers,
  12. getDigitsOnly,
  13. invitePeopleAndChatRooms
  14. } from './functions';
  15. const logger = require('jitsi-meet-logger').getLogger(__filename);
  16. /**
  17. * Creates a (redux) action to signal that a click/tap has been performed on
  18. * {@link InviteButton} and that the execution flow for adding/inviting people
  19. * to the current conference/meeting is to begin.
  20. *
  21. * @returns {{
  22. * type: BEGIN_ADD_PEOPLE
  23. * }}
  24. */
  25. export function beginAddPeople() {
  26. return {
  27. type: BEGIN_ADD_PEOPLE
  28. };
  29. }
  30. /**
  31. * Sends AJAX requests for dial-in numbers and conference ID.
  32. *
  33. * @returns {Function}
  34. */
  35. export function updateDialInNumbers() {
  36. return (dispatch: Dispatch<*>, getState: Function) => {
  37. const state = getState();
  38. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  39. = state['features/base/config'];
  40. const mucURL = hosts && hosts.muc;
  41. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  42. // URLs for fetching dial in numbers not defined
  43. return;
  44. }
  45. const { room } = state['features/base/conference'];
  46. Promise.all([
  47. getDialInNumbers(dialInNumbersUrl),
  48. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  49. ])
  50. .then(([ dialInNumbers, { conference, id, message } ]) => {
  51. if (!conference || !id) {
  52. return Promise.reject(message);
  53. }
  54. dispatch({
  55. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  56. conferenceID: id,
  57. dialInNumbers
  58. });
  59. })
  60. .catch(error => {
  61. dispatch({
  62. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  63. error
  64. });
  65. });
  66. };
  67. }
  68. /**
  69. * Send invites for a list of items (may be a combination of users, rooms, phone
  70. * numbers, and video rooms).
  71. *
  72. * @param {Array<Object>} invites - Items for which invites should be sent.
  73. * @returns {Promise} Promise containing the list of invites that were not sent.
  74. */
  75. export function sendInvitesForItems(invites: Array<Object>) {
  76. return (
  77. dispatch: Dispatch<*>,
  78. getState: Function): Promise<Array<Object>> => {
  79. let allInvitePromises = [];
  80. let invitesLeftToSend = [ ...invites ];
  81. const state = getState();
  82. const { conference } = state['features/base/conference'];
  83. const { inviteServiceUrl } = state['features/base/config'];
  84. const inviteUrl = getInviteURL(state);
  85. const jwt = state['features/base/jwt'].jwt;
  86. // First create all promises for dialing out.
  87. if (conference) {
  88. const phoneNumbers
  89. = invitesLeftToSend.filter(({ type }) => type === 'phone');
  90. // For each number, dial out. On success, remove the number from
  91. // {@link invitesLeftToSend}.
  92. const phoneInvitePromises = phoneNumbers.map(item => {
  93. const numberToInvite = getDigitsOnly(item.number);
  94. return conference.dial(numberToInvite)
  95. .then(() => {
  96. invitesLeftToSend
  97. = invitesLeftToSend.filter(invite =>
  98. invite !== item);
  99. })
  100. .catch(error => logger.error(
  101. 'Error inviting phone number:', error));
  102. });
  103. allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
  104. }
  105. const usersAndRooms = invitesLeftToSend.filter(item =>
  106. item.type === 'user' || item.type === 'room');
  107. if (usersAndRooms.length) {
  108. // Send a request to invite all the rooms and users. On success,
  109. // filter all rooms and users from {@link invitesLeftToSend}.
  110. const peopleInvitePromise = invitePeopleAndChatRooms(
  111. inviteServiceUrl,
  112. inviteUrl,
  113. jwt,
  114. usersAndRooms)
  115. .then(() => {
  116. invitesLeftToSend = invitesLeftToSend.filter(item =>
  117. item.type !== 'user' && item.type !== 'room');
  118. })
  119. .catch(error => logger.error(
  120. 'Error inviting people:', error));
  121. allInvitePromises.push(peopleInvitePromise);
  122. }
  123. // Sipgw calls are fire and forget. Invite them to the conference
  124. // then immediately remove them from {@link invitesLeftToSend}.
  125. const vrooms = invitesLeftToSend.filter(item =>
  126. item.type === 'videosipgw');
  127. conference
  128. && vrooms.length > 0
  129. && dispatch(inviteVideoRooms(conference, vrooms));
  130. invitesLeftToSend = invitesLeftToSend.filter(item =>
  131. item.type !== 'videosipgw');
  132. return (
  133. Promise.all(allInvitePromises)
  134. .then(() => invitesLeftToSend)
  135. );
  136. };
  137. }