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.ts 4.0KB

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