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 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // @flow
  2. import { CONFERENCE_WILL_JOIN } from '../conference';
  3. import { SET_CONFIG } from '../config';
  4. import { JitsiConferenceEvents } from '../lib-jitsi-meet';
  5. import { MiddlewareRegistry } from '../redux';
  6. import { getJitsiMeetGlobalNS } from '../util';
  7. import { setConnectionState } from './actions';
  8. import {
  9. getRemoteVideoType,
  10. isLargeVideoReceived,
  11. isRemoteVideoReceived,
  12. isTestModeEnabled
  13. } from './functions';
  14. import logger from './logger';
  15. /**
  16. * The Redux middleware of the feature testing.
  17. *
  18. * @param {Store} store - The Redux store.
  19. * @returns {Function}
  20. * @private
  21. */
  22. MiddlewareRegistry.register(store => next => action => {
  23. switch (action.type) {
  24. case CONFERENCE_WILL_JOIN:
  25. _bindConferenceConnectionListener(action.conference, store);
  26. break;
  27. case SET_CONFIG: {
  28. const result = next(action);
  29. _bindTortureHelpers(store);
  30. return result;
  31. }
  32. }
  33. return next(action);
  34. });
  35. /**
  36. * Binds a handler which will listen for the connection related conference
  37. * events (in the lib-jitsi-meet internals those are associated with the ICE
  38. * connection state).
  39. *
  40. * @param {JitsiConference} conference - The {@link JitsiConference} for which
  41. * the conference will join even is dispatched.
  42. * @param {Store} store - The redux store in which the specified action is being
  43. * dispatched.
  44. * @private
  45. * @returns {void}
  46. */
  47. function _bindConferenceConnectionListener(conference, { dispatch }) {
  48. conference.on(
  49. JitsiConferenceEvents.CONNECTION_ESTABLISHED,
  50. _onConnectionEvent.bind(
  51. null, JitsiConferenceEvents.CONNECTION_ESTABLISHED, dispatch));
  52. conference.on(
  53. JitsiConferenceEvents.CONNECTION_RESTORED,
  54. _onConnectionEvent.bind(
  55. null, JitsiConferenceEvents.CONNECTION_RESTORED, dispatch));
  56. conference.on(
  57. JitsiConferenceEvents.CONNECTION_INTERRUPTED,
  58. _onConnectionEvent.bind(
  59. null, JitsiConferenceEvents.CONNECTION_INTERRUPTED, dispatch));
  60. }
  61. /**
  62. * Binds all the helper functions needed by torture.
  63. *
  64. * @param {Store} store - The redux store.
  65. * @private
  66. * @returns {void}
  67. */
  68. function _bindTortureHelpers(store) {
  69. const { getState } = store;
  70. // We bind helpers only if testing mode is enabled
  71. if (!isTestModeEnabled(getState())) {
  72. return;
  73. }
  74. // All torture helper methods go in here
  75. getJitsiMeetGlobalNS().testing = {
  76. getRemoteVideoType: getRemoteVideoType.bind(null, store),
  77. isLargeVideoReceived: isLargeVideoReceived.bind(null, store),
  78. isRemoteVideoReceived: isRemoteVideoReceived.bind(null, store)
  79. };
  80. }
  81. /**
  82. * The handler function for conference connection events which will store the
  83. * latest even name in the Redux store of feature testing.
  84. *
  85. * @param {string} event - One of the lib-jitsi-meet JitsiConferenceEvents.
  86. * @param {Function} dispatch - The dispatch function of the current Redux
  87. * store.
  88. * @returns {void}
  89. * @private
  90. */
  91. function _onConnectionEvent(event, dispatch) {
  92. switch (event) {
  93. case JitsiConferenceEvents.CONNECTION_ESTABLISHED:
  94. case JitsiConferenceEvents.CONNECTION_INTERRUPTED:
  95. case JitsiConferenceEvents.CONNECTION_RESTORED:
  96. dispatch(setConnectionState(event));
  97. break;
  98. default:
  99. logger.error(`onConnectionEvent - unsupported event type: ${event}`);
  100. break;
  101. }
  102. }