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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. declare var config: Object;
  10. const CONFERENCE_ID_ENDPOINT = config.conferenceMapperUrl;
  11. const DIAL_IN_NUMBERS_ENDPOINT = config.dialInNumbersUrl;
  12. const MUC_URL = config && config.hosts && config.hosts.muc;
  13. /**
  14. * Opens the Invite Dialog.
  15. *
  16. * @returns {Function}
  17. */
  18. export function openInviteDialog() {
  19. return openDialog(InviteDialog, {
  20. conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl())
  21. });
  22. }
  23. /**
  24. * Sends an ajax requests for dial-in numbers and conference id.
  25. *
  26. * @returns {Function}
  27. */
  28. export function updateDialInNumbers() {
  29. return (dispatch, getState) => {
  30. if (!CONFERENCE_ID_ENDPOINT || !DIAL_IN_NUMBERS_ENDPOINT || !MUC_URL) {
  31. return;
  32. }
  33. const { room } = getState()['features/base/conference'];
  34. const conferenceIdUrl
  35. = `${CONFERENCE_ID_ENDPOINT}?conference=${room}@${MUC_URL}`;
  36. Promise.all([
  37. $.getJSON(DIAL_IN_NUMBERS_ENDPOINT),
  38. $.getJSON(conferenceIdUrl)
  39. ]).then(([ numbersResponse, idResponse ]) => {
  40. if (!idResponse.conference || !idResponse.id) {
  41. return Promise.reject(idResponse.message);
  42. }
  43. dispatch({
  44. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  45. conferenceId: idResponse,
  46. dialInNumbers: numbersResponse
  47. });
  48. })
  49. .catch(error => {
  50. dispatch({
  51. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  52. error
  53. });
  54. });
  55. };
  56. }