Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * Invites (i.e. sends invites to) an array of invitees (which may be a
  32. * combination of users, rooms, phone numbers, and video rooms).
  33. *
  34. * @param {Array<Object>} invitees - The recepients to send invites to.
  35. * @returns {Promise<Array<Object>>} A {@code Promise} resolving with an array
  36. * of invitees who were not invited (i.e. invites were not sent to them).
  37. */
  38. export function invite(invitees: Array<Object>) {
  39. return (
  40. dispatch: Dispatch<*>,
  41. getState: Function): Promise<Array<Object>> => {
  42. let allInvitePromises = [];
  43. let invitesLeftToSend = [ ...invitees ];
  44. const state = getState();
  45. const { conference } = state['features/base/conference'];
  46. const {
  47. callFlowsEnabled,
  48. inviteServiceUrl,
  49. inviteServiceCallFlowsUrl
  50. } = state['features/base/config'];
  51. const inviteUrl = getInviteURL(state);
  52. const { jwt } = state['features/base/jwt'];
  53. // First create all promises for dialing out.
  54. if (conference) {
  55. const phoneNumbers
  56. = invitesLeftToSend.filter(({ type }) => type === 'phone');
  57. // For each number, dial out. On success, remove the number from
  58. // {@link invitesLeftToSend}.
  59. const phoneInvitePromises = phoneNumbers.map(item => {
  60. const numberToInvite = getDigitsOnly(item.number);
  61. return conference.dial(numberToInvite)
  62. .then(() => {
  63. invitesLeftToSend
  64. = invitesLeftToSend.filter(
  65. invitee => invitee !== item);
  66. })
  67. .catch(error =>
  68. logger.error('Error inviting phone number:', error));
  69. });
  70. allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
  71. }
  72. const usersAndRooms
  73. = invitesLeftToSend.filter(
  74. ({ type }) => type === 'user' || type === 'room');
  75. if (usersAndRooms.length) {
  76. // Send a request to invite all the rooms and users. On success,
  77. // filter all rooms and users from {@link invitesLeftToSend}.
  78. const peopleInvitePromise
  79. = invitePeopleAndChatRooms(
  80. callFlowsEnabled
  81. ? inviteServiceCallFlowsUrl : inviteServiceUrl,
  82. inviteUrl,
  83. jwt,
  84. usersAndRooms)
  85. .then(() => {
  86. invitesLeftToSend
  87. = invitesLeftToSend.filter(
  88. ({ type }) => type !== 'user' && type !== 'room');
  89. })
  90. .catch(error => logger.error('Error inviting people:', error));
  91. allInvitePromises.push(peopleInvitePromise);
  92. }
  93. // Sipgw calls are fire and forget. Invite them to the conference, then
  94. // immediately remove them from invitesLeftToSend.
  95. const vrooms
  96. = invitesLeftToSend.filter(({ type }) => type === 'videosipgw');
  97. conference
  98. && vrooms.length > 0
  99. && dispatch(inviteVideoRooms(conference, vrooms));
  100. invitesLeftToSend
  101. = invitesLeftToSend.filter(({ type }) => type !== 'videosipgw');
  102. return (
  103. Promise.all(allInvitePromises)
  104. .then(() => invitesLeftToSend));
  105. };
  106. }
  107. /**
  108. * Sends AJAX requests for dial-in numbers and conference ID.
  109. *
  110. * @returns {Function}
  111. */
  112. export function updateDialInNumbers() {
  113. return (dispatch: Dispatch<*>, getState: Function) => {
  114. const state = getState();
  115. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  116. = state['features/base/config'];
  117. const mucURL = hosts && hosts.muc;
  118. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  119. // URLs for fetching dial in numbers not defined
  120. return;
  121. }
  122. const { room } = state['features/base/conference'];
  123. Promise.all([
  124. getDialInNumbers(dialInNumbersUrl),
  125. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  126. ])
  127. .then(([ dialInNumbers, { conference, id, message } ]) => {
  128. if (!conference || !id) {
  129. return Promise.reject(message);
  130. }
  131. dispatch({
  132. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  133. conferenceID: id,
  134. dialInNumbers
  135. });
  136. })
  137. .catch(error => {
  138. dispatch({
  139. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  140. error
  141. });
  142. });
  143. };
  144. }