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.web.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { IStore } from '../../app/types';
  2. import JitsiMeetJS from '../lib-jitsi-meet';
  3. import { SET_PRECALL_TEST_RESULTS, SET_UNSAFE_ROOM_CONSENT } from './actionTypes';
  4. import { getPreCallICEUrl } from './functions';
  5. import logger from './logger';
  6. import { IPreCallResult, IPreCallTestState, PreCallTestStatus } from './types';
  7. /**
  8. * Sets the consent of the user for joining the unsafe room.
  9. *
  10. * @param {boolean} consent - The user's consent.
  11. * @returns {{
  12. * type: SET_UNSAFE_ROOM_CONSENT,
  13. * consent: boolean
  14. * }}
  15. */
  16. export function setUnsafeRoomConsent(consent: boolean) {
  17. return {
  18. type: SET_UNSAFE_ROOM_CONSENT,
  19. consent
  20. };
  21. }
  22. /**
  23. * Initializes the 'precallTest' and executes one test, storing the results.
  24. *
  25. * @returns {Function}
  26. */
  27. export function runPreCallTest() {
  28. return async function(dispatch: Function, getState: IStore['getState']) {
  29. try {
  30. dispatch(setPreCallTestResults({ status: PreCallTestStatus.RUNNING }));
  31. const turnCredentialsUrl = getPreCallICEUrl(getState());
  32. if (!turnCredentialsUrl) {
  33. throw new Error('No TURN credentials URL provided in config');
  34. }
  35. const turnCredentials = await fetch(turnCredentialsUrl);
  36. const { iceServers } = await turnCredentials.json();
  37. const result: IPreCallResult = await JitsiMeetJS.runPreCallTest(iceServers);
  38. dispatch(setPreCallTestResults({ status: PreCallTestStatus.FINISHED,
  39. result }));
  40. } catch (error) {
  41. logger.error('Failed to run pre-call test', error);
  42. dispatch(setPreCallTestResults({ status: PreCallTestStatus.FAILED }));
  43. }
  44. };
  45. }
  46. /**
  47. * Action used to set data from precall test.
  48. *
  49. * @param {IPreCallTestState} value - The precall test results.
  50. * @returns {Object}
  51. */
  52. export function setPreCallTestResults(value: IPreCallTestState) {
  53. return {
  54. type: SET_PRECALL_TEST_RESULTS,
  55. value
  56. };
  57. }