Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.ts 3.5KB

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