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.

actions.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // @flow
  2. import {
  3. UPDATE_DIAL_IN_NUMBERS_FAILED,
  4. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  5. } from './actionTypes';
  6. import { getDialInConferenceID, getDialInNumbers } from './functions';
  7. /**
  8. * Sends AJAX requests for dial-in numbers and conference ID.
  9. *
  10. * @returns {Function}
  11. */
  12. export function updateDialInNumbers() {
  13. return (dispatch: Dispatch<*>, getState: Function) => {
  14. const state = getState();
  15. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  16. = state['features/base/config'];
  17. const mucURL = hosts && hosts.muc;
  18. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  19. // URLs for fetching dial in numbers not defined
  20. return;
  21. }
  22. const { room } = state['features/base/conference'];
  23. Promise.all([
  24. getDialInNumbers(dialInNumbersUrl),
  25. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  26. ])
  27. .then(([ dialInNumbers, { conference, id, message } ]) => {
  28. if (!conference || !id) {
  29. return Promise.reject(message);
  30. }
  31. dispatch({
  32. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  33. conferenceID: id,
  34. dialInNumbers
  35. });
  36. })
  37. .catch(error => {
  38. dispatch({
  39. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  40. error
  41. });
  42. });
  43. };
  44. }