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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { openDialog } from '../../features/base/dialog';
  2. import {
  3. UPDATE_DIAL_IN_NUMBERS_FAILED,
  4. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  5. } from './actionTypes';
  6. import { InviteDialog } from './components';
  7. declare var $: Function;
  8. declare var APP: Object;
  9. /**
  10. * Opens the Invite Dialog.
  11. *
  12. * @returns {Function}
  13. */
  14. export function openInviteDialog() {
  15. return openDialog(InviteDialog, {
  16. conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl())
  17. });
  18. }
  19. /**
  20. * Sends an ajax requests for dial-in numbers and conference id.
  21. *
  22. * @returns {Function}
  23. */
  24. export function updateDialInNumbers() {
  25. return (dispatch, getState) => {
  26. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  27. = getState()['features/base/config'];
  28. const mucUrl = hosts && hosts.muc;
  29. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucUrl) {
  30. dispatch({
  31. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  32. error: 'URLs for fetching dial in numbers not properly defined'
  33. });
  34. return;
  35. }
  36. const { room } = getState()['features/base/conference'];
  37. const conferenceIdUrl
  38. = `${dialInConfCodeUrl}?conference=${room}@${mucUrl}`;
  39. Promise.all([
  40. $.getJSON(dialInNumbersUrl),
  41. $.getJSON(conferenceIdUrl)
  42. ]).then(([ numbersResponse, idResponse ]) => {
  43. if (!idResponse.conference || !idResponse.id) {
  44. return Promise.reject(idResponse.message);
  45. }
  46. dispatch({
  47. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  48. conferenceId: idResponse,
  49. dialInNumbers: numbersResponse
  50. });
  51. })
  52. .catch(error => {
  53. dispatch({
  54. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  55. error
  56. });
  57. });
  58. };
  59. }