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.

actions.any.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { getInviteURL } from '../base/connection';
  4. import { getLocalParticipant, getParticipants } from '../base/participants';
  5. import { inviteVideoRooms } from '../videosipgw';
  6. import {
  7. ADD_PENDING_INVITE_REQUEST,
  8. BEGIN_ADD_PEOPLE,
  9. HIDE_ADD_PEOPLE_DIALOG,
  10. REMOVE_PENDING_INVITE_REQUESTS,
  11. SET_CALLEE_INFO_VISIBLE,
  12. UPDATE_DIAL_IN_NUMBERS_FAILED,
  13. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  14. } from './actionTypes';
  15. import {
  16. getDialInConferenceID,
  17. getDialInNumbers,
  18. invitePeopleAndChatRooms,
  19. inviteSipEndpoints
  20. } from './functions';
  21. import logger from './logger';
  22. /**
  23. * Creates a (redux) action to signal that a click/tap has been performed on
  24. * {@link InviteButton} and that the execution flow for adding/inviting people
  25. * to the current conference/meeting is to begin.
  26. *
  27. * @returns {{
  28. * type: BEGIN_ADD_PEOPLE
  29. * }}
  30. */
  31. export function beginAddPeople() {
  32. return {
  33. type: BEGIN_ADD_PEOPLE
  34. };
  35. }
  36. /**
  37. * Creates a (redux) action to signal that the {@code AddPeopleDialog}
  38. * should close.
  39. *
  40. * @returns {{
  41. * type: HIDE_ADD_PEOPLE_DIALOG
  42. * }}
  43. */
  44. export function hideAddPeopleDialog() {
  45. return {
  46. type: HIDE_ADD_PEOPLE_DIALOG
  47. };
  48. }
  49. /**
  50. * Invites (i.e. Sends invites to) an array of invitees (which may be a
  51. * combination of users, rooms, phone numbers, and video rooms.
  52. *
  53. * @param {Array<Object>} invitees - The recipients to send invites to.
  54. * @param {Array<Object>} showCalleeInfo - Indicates whether the
  55. * {@code CalleeInfo} should be displayed or not.
  56. * @returns {Promise<Array<Object>>} A {@code Promise} resolving with an array
  57. * of invitees who were not invited (i.e. Invites were not sent to them).
  58. */
  59. export function invite(
  60. invitees: Array<Object>,
  61. showCalleeInfo: boolean = false) {
  62. return (
  63. dispatch: Dispatch<any>,
  64. getState: Function): Promise<Array<Object>> => {
  65. const state = getState();
  66. const participants = getParticipants(state);
  67. const { calleeInfoVisible } = state['features/invite'];
  68. if (showCalleeInfo
  69. && !calleeInfoVisible
  70. && invitees.length === 1
  71. && invitees[0].type === 'user'
  72. && participants.length === 1) {
  73. dispatch(setCalleeInfoVisible(true, invitees[0]));
  74. }
  75. const { conference } = state['features/base/conference'];
  76. if (typeof conference === 'undefined') {
  77. // Invite will fail before CONFERENCE_JOIN. The request will be
  78. // cached in order to be executed on CONFERENCE_JOIN.
  79. return new Promise(resolve => {
  80. dispatch(addPendingInviteRequest({
  81. invitees,
  82. callback: failedInvitees => resolve(failedInvitees)
  83. }));
  84. });
  85. }
  86. let allInvitePromises = [];
  87. let invitesLeftToSend = [ ...invitees ];
  88. const {
  89. callFlowsEnabled,
  90. inviteServiceUrl,
  91. inviteServiceCallFlowsUrl
  92. } = state['features/base/config'];
  93. const inviteUrl = getInviteURL(state);
  94. const { sipInviteUrl } = state['features/base/config'];
  95. const { jwt } = state['features/base/jwt'];
  96. const { name: displayName } = getLocalParticipant(state);
  97. // First create all promises for dialing out.
  98. const phoneNumbers
  99. = invitesLeftToSend.filter(({ type }) => type === 'phone');
  100. // For each number, dial out. On success, remove the number from
  101. // {@link invitesLeftToSend}.
  102. const phoneInvitePromises = phoneNumbers.map(item => {
  103. const numberToInvite = item.number;
  104. return conference.dial(numberToInvite)
  105. .then(() => {
  106. invitesLeftToSend
  107. = invitesLeftToSend.filter(
  108. invitee => invitee !== item);
  109. })
  110. .catch(error =>
  111. logger.error('Error inviting phone number:', error));
  112. });
  113. allInvitePromises = allInvitePromises.concat(phoneInvitePromises);
  114. const usersAndRooms
  115. = invitesLeftToSend.filter(
  116. ({ type }) => type === 'user' || type === 'room');
  117. if (usersAndRooms.length) {
  118. // Send a request to invite all the rooms and users. On success,
  119. // filter all rooms and users from {@link invitesLeftToSend}.
  120. const peopleInvitePromise
  121. = invitePeopleAndChatRooms(
  122. callFlowsEnabled
  123. ? inviteServiceCallFlowsUrl : inviteServiceUrl,
  124. inviteUrl,
  125. jwt,
  126. usersAndRooms)
  127. .then(() => {
  128. invitesLeftToSend
  129. = invitesLeftToSend.filter(
  130. ({ type }) => type !== 'user' && type !== 'room');
  131. })
  132. .catch(error => {
  133. dispatch(setCalleeInfoVisible(false));
  134. logger.error('Error inviting people:', error);
  135. });
  136. allInvitePromises.push(peopleInvitePromise);
  137. }
  138. // Sipgw calls are fire and forget. Invite them to the conference, then
  139. // immediately remove them from invitesLeftToSend.
  140. const vrooms
  141. = invitesLeftToSend.filter(({ type }) => type === 'videosipgw');
  142. conference
  143. && vrooms.length > 0
  144. && dispatch(inviteVideoRooms(conference, vrooms));
  145. invitesLeftToSend
  146. = invitesLeftToSend.filter(({ type }) => type !== 'videosipgw');
  147. const sipEndpoints
  148. = invitesLeftToSend.filter(({ type }) => type === 'sip');
  149. conference && inviteSipEndpoints(
  150. sipEndpoints,
  151. sipInviteUrl,
  152. jwt,
  153. conference.options.name,
  154. displayName
  155. );
  156. invitesLeftToSend
  157. = invitesLeftToSend.filter(({ type }) => type !== 'sip');
  158. return (
  159. Promise.all(allInvitePromises)
  160. .then(() => invitesLeftToSend));
  161. };
  162. }
  163. /**
  164. * Sends AJAX requests for dial-in numbers and conference ID.
  165. *
  166. * @returns {Function}
  167. */
  168. export function updateDialInNumbers() {
  169. return (dispatch: Dispatch<any>, getState: Function) => {
  170. const state = getState();
  171. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  172. = state['features/base/config'];
  173. const { numbersFetched } = state['features/invite'];
  174. const mucURL = hosts && hosts.muc;
  175. if (numbersFetched || !dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  176. // URLs for fetching dial in numbers not defined
  177. return;
  178. }
  179. const { room } = state['features/base/conference'];
  180. Promise.all([
  181. getDialInNumbers(dialInNumbersUrl, room, mucURL),
  182. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  183. ])
  184. .then(([ dialInNumbers, { conference, id, message } ]) => {
  185. if (!conference || !id) {
  186. return Promise.reject(message);
  187. }
  188. dispatch({
  189. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  190. conferenceID: id,
  191. dialInNumbers
  192. });
  193. })
  194. .catch(error => {
  195. dispatch({
  196. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  197. error
  198. });
  199. });
  200. };
  201. }
  202. /**
  203. * Sets the visibility of {@code CalleeInfo}.
  204. *
  205. * @param {boolean|undefined} [calleeInfoVisible] - If {@code CalleeInfo} is
  206. * to be displayed/visible, then {@code true}; otherwise, {@code false} or
  207. * {@code undefined}.
  208. * @param {Object|undefined} [initialCalleeInfo] - Callee information.
  209. * @returns {{
  210. * type: SET_CALLEE_INFO_VISIBLE,
  211. * calleeInfoVisible: (boolean|undefined),
  212. * initialCalleeInfo
  213. * }}
  214. */
  215. export function setCalleeInfoVisible(
  216. calleeInfoVisible: boolean,
  217. initialCalleeInfo: ?Object) {
  218. return {
  219. type: SET_CALLEE_INFO_VISIBLE,
  220. calleeInfoVisible,
  221. initialCalleeInfo
  222. };
  223. }
  224. /**
  225. * Adds pending invite request.
  226. *
  227. * @param {Object} request - The request.
  228. * @returns {{
  229. * type: ADD_PENDING_INVITE_REQUEST,
  230. * request: Object
  231. * }}
  232. */
  233. export function addPendingInviteRequest(
  234. request: { invitees: Array<Object>, callback: Function }) {
  235. return {
  236. type: ADD_PENDING_INVITE_REQUEST,
  237. request
  238. };
  239. }
  240. /**
  241. * Removes all pending invite requests.
  242. *
  243. * @returns {{
  244. * type: REMOVE_PENDING_INVITE_REQUEST
  245. * }}
  246. */
  247. export function removePendingInviteRequests() {
  248. return {
  249. type: REMOVE_PENDING_INVITE_REQUESTS
  250. };
  251. }