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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @flow
  2. import { openDialog } from '../../features/base/dialog';
  3. import {
  4. SET_INFO_DIALOG_VISIBILITY,
  5. UPDATE_DIAL_IN_NUMBERS_FAILED,
  6. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  7. } from './actionTypes';
  8. import { InviteDialog } from './components';
  9. declare var $: Function;
  10. /**
  11. * Opens the Invite Dialog.
  12. *
  13. * @returns {Function}
  14. */
  15. export function openInviteDialog() {
  16. return openDialog(InviteDialog);
  17. }
  18. /**
  19. * Opens the inline conference info dialog.
  20. *
  21. * @param {boolean} visible - Whether or not the dialog should be displayed.
  22. * @returns {{
  23. * type: SET_INFO_DIALOG_VISIBILITY,
  24. * visible: boolean
  25. * }}
  26. */
  27. export function setInfoDialogVisibility(visible: boolean) {
  28. return {
  29. type: SET_INFO_DIALOG_VISIBILITY,
  30. visible
  31. };
  32. }
  33. /**
  34. * Sends AJAX requests for dial-in numbers and conference ID.
  35. *
  36. * @returns {Function}
  37. */
  38. export function updateDialInNumbers() {
  39. return (dispatch: Dispatch<*>, getState: Function) => {
  40. const state = getState();
  41. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  42. = state['features/base/config'];
  43. const mucURL = hosts && hosts.muc;
  44. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  45. // URLs for fetching dial in numbers not defined
  46. return;
  47. }
  48. const { room } = state['features/base/conference'];
  49. const conferenceIDURL
  50. = `${dialInConfCodeUrl}?conference=${room}@${mucURL}`;
  51. Promise.all([
  52. $.getJSON(dialInNumbersUrl),
  53. $.getJSON(conferenceIDURL)
  54. ])
  55. .then(([ dialInNumbers, { conference, id, message } ]) => {
  56. if (!conference || !id) {
  57. return Promise.reject(message);
  58. }
  59. dispatch({
  60. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  61. conferenceID: id,
  62. dialInNumbers
  63. });
  64. })
  65. .catch(error => {
  66. dispatch({
  67. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  68. error
  69. });
  70. });
  71. };
  72. }