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

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