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

middleware.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import { MiddlewareRegistry } from '../redux';
  3. import { CONFERENCE_WILL_JOIN } from '../conference';
  4. import { JitsiConferenceEvents } from '../lib-jitsi-meet';
  5. import { setConnectionState } from './actions';
  6. import logger from './logger';
  7. /**
  8. * The Redux middleware of the feature testing.
  9. *
  10. * @param {Store} store - The Redux store.
  11. * @returns {Function}
  12. * @private
  13. */
  14. MiddlewareRegistry.register(store => next => action => {
  15. switch (action.type) {
  16. case CONFERENCE_WILL_JOIN:
  17. _bindConferenceConnectionListener(action.conference, store);
  18. break;
  19. }
  20. return next(action);
  21. });
  22. /**
  23. * Binds a handler which will listen for the connection related conference
  24. * events (in the lib-jitsi-meet internals those are associated with the ICE
  25. * connection state).
  26. *
  27. * @param {JitsiConference} conference - The {@link JitsiConference} for which
  28. * the conference will join even is dispatched.
  29. * @param {Store} store - The redux store in which the specified action is being
  30. * dispatched.
  31. * @private
  32. * @returns {void}
  33. */
  34. function _bindConferenceConnectionListener(conference, { dispatch }) {
  35. conference.on(
  36. JitsiConferenceEvents.CONNECTION_ESTABLISHED,
  37. _onConnectionEvent.bind(
  38. null, JitsiConferenceEvents.CONNECTION_ESTABLISHED, dispatch));
  39. conference.on(
  40. JitsiConferenceEvents.CONNECTION_RESTORED,
  41. _onConnectionEvent.bind(
  42. null, JitsiConferenceEvents.CONNECTION_RESTORED, dispatch));
  43. conference.on(
  44. JitsiConferenceEvents.CONNECTION_INTERRUPTED,
  45. _onConnectionEvent.bind(
  46. null, JitsiConferenceEvents.CONNECTION_INTERRUPTED, dispatch));
  47. }
  48. /**
  49. * The handler function for conference connection events which wil store the
  50. * latest even name in the Redux store of feature testing.
  51. *
  52. * @param {string} event - One of the lib-jitsi-meet JitsiConferenceEvents.
  53. * @param {Function} dispatch - The dispatch function of the current Redux
  54. * store.
  55. * @returns {void}
  56. * @private
  57. */
  58. function _onConnectionEvent(event, dispatch) {
  59. switch (event) {
  60. case JitsiConferenceEvents.CONNECTION_ESTABLISHED:
  61. case JitsiConferenceEvents.CONNECTION_INTERRUPTED:
  62. case JitsiConferenceEvents.CONNECTION_RESTORED:
  63. dispatch(setConnectionState(event));
  64. break;
  65. default:
  66. logger.error(`onConnectionEvent - unsupported event type: ${event}`);
  67. break;
  68. }
  69. }