Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* eslint-disable lines-around-comment */
  2. import { IStore } from '../app/types';
  3. import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
  4. import {
  5. isFatalJitsiConferenceError,
  6. isFatalJitsiConnectionError
  7. } from '../base/lib-jitsi-meet/functions.any';
  8. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  9. import { openPageReloadDialog } from './actions';
  10. /**
  11. * Error type. Basically like Error, but augmented with a recoverable property.
  12. */
  13. type ErrorType = {
  14. /**
  15. * Error message.
  16. */
  17. message?: string;
  18. /**
  19. * Error name.
  20. */
  21. name: string;
  22. /**
  23. * Indicates whether this event is recoverable or not.
  24. */
  25. recoverable?: boolean;
  26. };
  27. /**
  28. * List of errors that are not fatal (or handled differently) so then the overlays won't kick in.
  29. */
  30. const NON_OVERLAY_ERRORS = [
  31. JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED,
  32. JitsiConferenceErrors.CONFERENCE_DESTROYED,
  33. JitsiConferenceErrors.CONNECTION_ERROR
  34. ];
  35. const ERROR_TYPES = {
  36. CONFIG: 'CONFIG',
  37. CONNECTION: 'CONNECTION',
  38. CONFERENCE: 'CONFERENCE'
  39. };
  40. /**
  41. * Gets the error type and whether it's fatal or not.
  42. *
  43. * @param {Object} state - The redux state.
  44. * @param {Object|string} error - The error to process.
  45. * @returns {void}
  46. */
  47. const getErrorExtraInfo = (state: any, error: ErrorType) => {
  48. const { error: conferenceError } = state['features/base/conference'];
  49. const { error: configError } = state['features/base/config'];
  50. const { error: connectionError } = state['features/base/connection'];
  51. if (error === conferenceError) {
  52. return {
  53. type: ERROR_TYPES.CONFERENCE, // @ts-ignore
  54. isFatal: isFatalJitsiConferenceError(error.name || error)
  55. };
  56. }
  57. if (error === configError) {
  58. return {
  59. type: ERROR_TYPES.CONFIG,
  60. isFatal: true
  61. };
  62. }
  63. if (error === connectionError) {
  64. return {
  65. type: ERROR_TYPES.CONNECTION, // @ts-ignore
  66. isFatal: isFatalJitsiConnectionError(error.name || error)
  67. };
  68. }
  69. };
  70. /**
  71. * State listener which emits the {@code fatalErrorOccurred} action which works
  72. * as a catch all for critical errors which have not been claimed by any other
  73. * feature for error recovery (the recoverable flag is not set).
  74. */
  75. StateListenerRegistry.register(
  76. /* selector */ state => {
  77. const { error: conferenceError } = state['features/base/conference'];
  78. const { error: configError } = state['features/base/config'];
  79. const { error: connectionError } = state['features/base/connection'];
  80. return configError || connectionError || conferenceError;
  81. },
  82. /* listener */ (error: ErrorType, store: IStore) => {
  83. const state = store.getState();
  84. if (!error) {
  85. return;
  86. }
  87. // eslint-disable-next-line no-negated-condition
  88. if (typeof APP !== 'undefined') {
  89. APP.API.notifyError({
  90. ...error,
  91. ...getErrorExtraInfo(state, error)
  92. });
  93. }
  94. if (NON_OVERLAY_ERRORS.indexOf(error.name) === -1 && typeof error.recoverable === 'undefined') {
  95. setTimeout(() => {
  96. // @ts-ignore
  97. store.dispatch(openPageReloadDialog());
  98. }, 500);
  99. }
  100. }
  101. );