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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {
  2. DIAL_OUT_CANCELED,
  3. DIAL_OUT_CODES_UPDATED,
  4. DIAL_OUT_SERVICE_FAILED,
  5. PHONE_NUMBER_CHECKED
  6. } from './actionTypes';
  7. declare var $: Function;
  8. declare var config: Object;
  9. /**
  10. * Dials the given number.
  11. *
  12. * @returns {Function}
  13. */
  14. export function cancel() {
  15. return {
  16. type: DIAL_OUT_CANCELED
  17. };
  18. }
  19. /**
  20. * Dials the given number.
  21. *
  22. * @param {string} dialNumber - The number to dial.
  23. * @returns {Function}
  24. */
  25. export function dial(dialNumber) {
  26. return (dispatch, getState) => {
  27. const { conference } = getState()['features/base/conference'];
  28. conference.dial(dialNumber);
  29. };
  30. }
  31. /**
  32. * Sends an ajax request for dial-out country codes.
  33. *
  34. * @param {string} dialNumber - The dial number to check for validity.
  35. * @returns {Function}
  36. */
  37. export function checkDialNumber(dialNumber) {
  38. return (dispatch, getState) => {
  39. const { dialOutAuthUrl } = getState()['features/base/config'];
  40. if (!dialOutAuthUrl) {
  41. // no auth url, let's say it is valid
  42. const response = {};
  43. response.allow = true;
  44. dispatch({
  45. type: PHONE_NUMBER_CHECKED,
  46. response
  47. });
  48. return;
  49. }
  50. const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
  51. $.getJSON(fullUrl)
  52. .success(response =>
  53. dispatch({
  54. type: PHONE_NUMBER_CHECKED,
  55. response
  56. }))
  57. .error(error =>
  58. dispatch({
  59. type: DIAL_OUT_SERVICE_FAILED,
  60. error
  61. }));
  62. };
  63. }
  64. /**
  65. * Sends an ajax request for dial-out country codes.
  66. *
  67. * @returns {Function}
  68. */
  69. export function updateDialOutCodes() {
  70. return (dispatch, getState) => {
  71. const { dialOutCodesUrl } = getState()['features/base/config'];
  72. if (!dialOutCodesUrl) {
  73. return;
  74. }
  75. $.getJSON(dialOutCodesUrl)
  76. .success(response =>
  77. dispatch({
  78. type: DIAL_OUT_CODES_UPDATED,
  79. response
  80. }))
  81. .error(error =>
  82. dispatch({
  83. type: DIAL_OUT_SERVICE_FAILED,
  84. error
  85. }));
  86. };
  87. }