Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import {
  4. CONFERENCE_JOINED,
  5. E2E_RTT_CHANGED
  6. } from '../base/conference/actionTypes';
  7. import { DOMINANT_SPEAKER_CHANGED } from '../base/participants/actionTypes';
  8. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  9. import { TRACK_ADDED, TRACK_UPDATED } from '../base/tracks/actionTypes';
  10. import { ADD_FACE_LANDMARKS } from '../face-landmarks/actionTypes';
  11. import { FaceLandmarks } from '../face-landmarks/types';
  12. import { sendGetCustomerIdRequest } from '../jaas/functions';
  13. import RTCStats from './RTCStats';
  14. import {
  15. canSendFaceLandmarksRTCStatsData,
  16. isRTCStatsEnabled
  17. } from './functions';
  18. import logger from './logger';
  19. /**
  20. * Middleware which intercepts lib-jitsi-meet initialization and conference join in order init the
  21. * rtcstats-client.
  22. *
  23. * @param {Store} store - The redux store.
  24. * @returns {Function}
  25. */
  26. MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyAction) => {
  27. const { getState } = store;
  28. const state = getState();
  29. switch (action.type) {
  30. case CONFERENCE_JOINED: {
  31. if (isRTCStatsEnabled(state)) {
  32. RTCStats.init();
  33. sendGetCustomerIdRequest(action?.conference, state)
  34. .then(customerData => {
  35. const { customerId } = customerData ?? {};
  36. customerId && RTCStats.sendIdentityData({ customerId });
  37. })
  38. .catch(error => {
  39. logger.error('Error while getting customer id:', error);
  40. });
  41. }
  42. break;
  43. }
  44. case TRACK_ADDED: {
  45. if (isRTCStatsEnabled(state)) {
  46. const jitsiTrack = action?.track?.jitsiTrack;
  47. const { ssrc, videoType } = jitsiTrack || { };
  48. // Remote tracks store their ssrc in the jitsiTrack object. Local tracks don't. See getSsrcByTrack.
  49. if (videoType && ssrc && !jitsiTrack.isLocal() && !jitsiTrack.isAudioTrack()) {
  50. RTCStats.sendVideoTypeData({
  51. ssrc,
  52. videoType
  53. });
  54. }
  55. }
  56. break;
  57. }
  58. case TRACK_UPDATED: {
  59. if (isRTCStatsEnabled(state)) {
  60. const { videoType, jitsiTrack, muted } = action?.track || { };
  61. const { ssrc, isLocal, videoType: trackVideoType, conference } = jitsiTrack || { };
  62. if (trackVideoType === 'camera' && conference && isLocal()) {
  63. RTCStats.sendFaceLandmarksData({
  64. duration: 0,
  65. faceLandmarks: muted ? 'camera-off' : 'camera-on',
  66. timestamp: Date.now()
  67. });
  68. }
  69. // if the videoType of the remote track has changed we expect to find it in track.videoType. grep for
  70. // trackVideoTypeChanged.
  71. if (videoType && ssrc && !jitsiTrack.isLocal() && !jitsiTrack.isAudioTrack()) {
  72. RTCStats.sendVideoTypeData({
  73. ssrc,
  74. videoType
  75. });
  76. }
  77. }
  78. break;
  79. }
  80. case DOMINANT_SPEAKER_CHANGED: {
  81. if (isRTCStatsEnabled(state)) {
  82. const { id, previousSpeakers, silence } = action.participant;
  83. RTCStats.sendDominantSpeakerData({
  84. dominantSpeakerEndpoint: silence ? null : id,
  85. previousSpeakers
  86. });
  87. }
  88. break;
  89. }
  90. case E2E_RTT_CHANGED: {
  91. if (isRTCStatsEnabled(state)) {
  92. const { participant, rtt } = action.e2eRtt;
  93. RTCStats.sendE2ERTTData({
  94. remoteEndpointId: participant.getId(),
  95. rtt,
  96. remoteRegion: participant.getProperty('region')
  97. });
  98. }
  99. break;
  100. }
  101. case ADD_FACE_LANDMARKS: {
  102. if (canSendFaceLandmarksRTCStatsData(state)) {
  103. const { duration, faceExpression, timestamp } = action.faceLandmarks as FaceLandmarks;
  104. const durationSeconds = Math.round(duration / 1000);
  105. RTCStats.sendFaceLandmarksData({
  106. duration: durationSeconds,
  107. faceLandmarks: faceExpression,
  108. timestamp
  109. });
  110. }
  111. break;
  112. }
  113. }
  114. return next(action);
  115. });