您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @flow
  2. import {
  3. JitsiConferenceErrors,
  4. isFatalJitsiConferenceError,
  5. isFatalJitsiConnectionError
  6. } from '../base/lib-jitsi-meet';
  7. import { StateListenerRegistry } from '../base/redux';
  8. import { setFatalError } from './actions';
  9. declare var APP: Object;
  10. /**
  11. * List of errors that are not fatal (or handled differently) so then the overlays won't kick in.
  12. */
  13. const NON_OVERLAY_ERRORS = [
  14. JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED,
  15. JitsiConferenceErrors.CONFERENCE_DESTROYED,
  16. JitsiConferenceErrors.CONNECTION_ERROR
  17. ];
  18. const ERROR_TYPES = {
  19. CONFIG: 'CONFIG',
  20. CONNECTION: 'CONNECTION',
  21. CONFERENCE: 'CONFERENCE'
  22. };
  23. /**
  24. * Gets the error type and whether it's fatal or not.
  25. *
  26. * @param {Function} getState - The redux function for fetching the current state.
  27. * @param {Object|string} error - The error to process.
  28. * @returns {void}
  29. */
  30. const getErrorExtraInfo = (getState, error) => {
  31. const state = getState();
  32. const { error: conferenceError } = state['features/base/conference'];
  33. const { error: configError } = state['features/base/config'];
  34. const { error: connectionError } = state['features/base/connection'];
  35. if (error === conferenceError) {
  36. return {
  37. type: ERROR_TYPES.CONFERENCE,
  38. isFatal: isFatalJitsiConferenceError(error.name || error)
  39. };
  40. }
  41. if (error === configError) {
  42. return {
  43. type: ERROR_TYPES.CONFIG,
  44. isFatal: true
  45. };
  46. }
  47. if (error === connectionError) {
  48. return {
  49. type: ERROR_TYPES.CONNECTION,
  50. isFatal: isFatalJitsiConnectionError(error.name || error)
  51. };
  52. }
  53. };
  54. /**
  55. * State listener which emits the {@code fatalErrorOccurred} action which works
  56. * as a catch all for critical errors which have not been claimed by any other
  57. * feature for error recovery (the recoverable flag is not set).
  58. */
  59. StateListenerRegistry.register(
  60. /* selector */ state => {
  61. const { error: conferenceError } = state['features/base/conference'];
  62. const { error: configError } = state['features/base/config'];
  63. const { error: connectionError } = state['features/base/connection'];
  64. return configError || connectionError || conferenceError;
  65. },
  66. /* listener */ (error, { dispatch, getState }) => {
  67. if (!error) {
  68. return;
  69. }
  70. if (typeof APP !== 'undefined') {
  71. const parsedError = typeof error === 'string' ? { name: error } : error;
  72. APP.API.notifyError({
  73. ...parsedError,
  74. ...getErrorExtraInfo(getState, error)
  75. });
  76. }
  77. if (NON_OVERLAY_ERRORS.indexOf(error.name) === -1 && typeof error.recoverable === 'undefined') {
  78. dispatch(setFatalError(error));
  79. }
  80. }
  81. );