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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  11. * The url for the api that matches a conference name and muc to an id.
  12. *
  13. * @type {string}
  14. */
  15. const DIAL_IN_CONF_CODE_URL = config.dialInConfCodeUrl;
  16. /**
  17. * The url for the api that returns phone numbers to dial in to the conference
  18. * and join using the conference id.
  19. *
  20. * @type {string}
  21. */
  22. const DIAL_IN_NUMBERS_URLS = config.dialInNumbersUrl;
  23. /**
  24. * The url for the MUC component joined for the conference.
  25. *
  26. * @type {string}
  27. */
  28. const MUC_URL = config.hosts && config.hosts.muc;
  29. /**
  30. * Opens the Invite Dialog.
  31. *
  32. * @returns {Function}
  33. */
  34. export function openInviteDialog() {
  35. return openDialog(InviteDialog, {
  36. conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl())
  37. });
  38. }
  39. /**
  40. * Sends an ajax requests for dial-in numbers and conference id.
  41. *
  42. * @returns {Function}
  43. */
  44. export function updateDialInNumbers() {
  45. return (dispatch, getState) => {
  46. if (!DIAL_IN_CONF_CODE_URL || !DIAL_IN_NUMBERS_URLS || !MUC_URL) {
  47. dispatch({
  48. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  49. error: 'URLs for fetching dial in numbers not properly defined'
  50. });
  51. return;
  52. }
  53. const { room } = getState()['features/base/conference'];
  54. const conferenceIdUrl
  55. = `${DIAL_IN_CONF_CODE_URL}?conference=${room}@${MUC_URL}`;
  56. Promise.all([
  57. $.getJSON(DIAL_IN_NUMBERS_URLS),
  58. $.getJSON(conferenceIdUrl)
  59. ]).then(([ numbersResponse, idResponse ]) => {
  60. if (!idResponse.conference || !idResponse.id) {
  61. return Promise.reject(idResponse.message);
  62. }
  63. dispatch({
  64. type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
  65. conferenceId: idResponse,
  66. dialInNumbers: numbersResponse
  67. });
  68. })
  69. .catch(error => {
  70. dispatch({
  71. type: UPDATE_DIAL_IN_NUMBERS_FAILED,
  72. error
  73. });
  74. });
  75. };
  76. }