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.

middleware.js 2.4KB

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