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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {
  2. CONFERENCE_JOINED,
  3. CONFERENCE_WILL_LEAVE,
  4. getCurrentConference
  5. } from '../base/conference';
  6. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  7. import { MiddlewareRegistry } from '../base/redux';
  8. import { TRACK_UPDATED, TRACK_REMOVED, TRACK_ADDED } from '../base/tracks';
  9. import { UPDATE_FACE_COORDINATES } from './actionTypes';
  10. import {
  11. loadWorker,
  12. stopFaceRecognition,
  13. startFaceRecognition
  14. } from './actions';
  15. import { FACE_BOX_EVENT_TYPE } from './constants';
  16. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  17. const state = getState();
  18. const { faceCoordinatesSharing } = state['features/base/config'];
  19. if (!getCurrentConference(state)) {
  20. return next(action);
  21. }
  22. if (action.type === CONFERENCE_JOINED) {
  23. if (faceCoordinatesSharing?.enabled) {
  24. dispatch(loadWorker());
  25. }
  26. // allow using remote face centering data when local face centering is not enabled
  27. action.conference.on(
  28. JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
  29. (participant, eventData) => {
  30. if (!participant || !eventData) {
  31. return;
  32. }
  33. if (eventData.type === FACE_BOX_EVENT_TYPE) {
  34. dispatch({
  35. type: UPDATE_FACE_COORDINATES,
  36. faceBox: eventData.faceBox,
  37. id: participant.getId()
  38. });
  39. }
  40. });
  41. return next(action);
  42. }
  43. if (!faceCoordinatesSharing?.enabled) {
  44. return next(action);
  45. }
  46. switch (action.type) {
  47. case CONFERENCE_WILL_LEAVE : {
  48. dispatch(stopFaceRecognition());
  49. return next(action);
  50. }
  51. case TRACK_ADDED: {
  52. const { jitsiTrack: { isLocal, videoType } } = action.track;
  53. if (videoType === 'camera' && isLocal()) {
  54. // need to pass this since the track is not yet added in the store
  55. dispatch(startFaceRecognition(action.track));
  56. }
  57. return next(action);
  58. }
  59. case TRACK_UPDATED: {
  60. const { jitsiTrack: { isLocal, videoType } } = action.track;
  61. if (videoType !== 'camera' || !isLocal()) {
  62. return next(action);
  63. }
  64. const { muted } = action.track;
  65. if (muted !== undefined) {
  66. // addresses video mute state changes
  67. if (muted) {
  68. dispatch(stopFaceRecognition());
  69. } else {
  70. dispatch(startFaceRecognition());
  71. }
  72. }
  73. return next(action);
  74. }
  75. case TRACK_REMOVED: {
  76. const { jitsiTrack: { isLocal, videoType } } = action.track;
  77. if (videoType === 'camera' && isLocal()) {
  78. dispatch(stopFaceRecognition());
  79. }
  80. return next(action);
  81. }
  82. }
  83. return next(action);
  84. });