Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @ts-expect-error
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import { getAmplitudeIdentity } from '../analytics/functions';
  4. import { IStore } from '../app/types';
  5. import { IStateful } from '../base/app/types';
  6. import { getAnalyticsRoomName, getConferenceOptions } from '../base/conference/functions';
  7. import { getLocalParticipant } from '../base/participants/functions';
  8. import { toState } from '../base/redux/functions';
  9. import RTCStats from './RTCStats';
  10. import logger from './logger';
  11. /**
  12. * Checks whether rtcstats is enabled or not.
  13. *
  14. * @param {IStateful} stateful - The redux store or {@code getState} function.
  15. * @returns {boolean}
  16. */
  17. export function isRtcstatsEnabled(stateful: IStateful) {
  18. const state = toState(stateful);
  19. const { analytics } = state['features/base/config'];
  20. return analytics?.rtcstatsEnabled ?? false;
  21. }
  22. /**
  23. * Can the rtcstats service send data.
  24. *
  25. * @param {IStateful} stateful - The redux store or {@code getState} function.
  26. * @returns {boolean}
  27. */
  28. export function canSendRtcstatsData(stateful: IStateful) {
  29. return isRtcstatsEnabled(stateful) && RTCStats.isInitialized();
  30. }
  31. type Identity = {
  32. isBreakoutRoom: boolean;
  33. // Unique identifier for a conference session, not to be confused with meeting name
  34. // i.e. If all participants leave a meeting it will have a different value on the next join.
  35. meetingUniqueId?: string;
  36. roomId?: string;
  37. };
  38. /**
  39. * Connects to the rtcstats service and sends the identity data.
  40. *
  41. * @param {IStore} store - Redux Store.
  42. * @param {Identity} identity - Identity data for the client.
  43. * @returns {void}
  44. */
  45. export function connectAndSendIdentity({ getState, dispatch }: IStore, identity: Identity) {
  46. const state = getState();
  47. if (canSendRtcstatsData(state)) {
  48. // Once the conference started connect to the rtcstats server and send data.
  49. try {
  50. RTCStats.connect(identity.isBreakoutRoom);
  51. const localParticipant = getLocalParticipant(state);
  52. const options = getConferenceOptions(state);
  53. // The current implementation of rtcstats-server is configured to send data to amplitude, thus
  54. // we add identity specific information so we can correlate on the amplitude side. If amplitude is
  55. // not configured an empty object will be sent.
  56. // The current configuration of the conference is also sent as metadata to rtcstats server.
  57. // This is done in order to facilitate queries based on different conference configurations.
  58. // e.g. Find all RTCPeerConnections that connect to a specific shard or were created in a
  59. // conference with a specific version.
  60. let displayName = jitsiLocalStorage.getItem('callStatsUserName');
  61. if (options.statisticsId || options.statisticsDisplayName) {
  62. if (options.statisticsId && options.statisticsDisplayName) {
  63. displayName = `${options.statisticsDisplayName} (${options.statisticsId})`;
  64. } else {
  65. displayName = options.statisticsId || options.statisticsDisplayName;
  66. }
  67. }
  68. RTCStats.sendIdentityData({
  69. ...getAmplitudeIdentity(),
  70. ...options,
  71. endpointId: localParticipant?.id,
  72. confName: getAnalyticsRoomName(state, dispatch),
  73. displayName,
  74. ...identity
  75. });
  76. } catch (error) {
  77. // If the connection failed do not impact jitsi-meet just silently fail.
  78. logger.error('RTCStats connect failed with: ', error);
  79. }
  80. }
  81. }
  82. /**
  83. * Checks if the faceLandmarks data can be sent to the rtcstats server.
  84. *
  85. * @param {IStateful} stateful - The redux store or {@code getState} function.
  86. * @returns {boolean}
  87. */
  88. export function canSendFaceLandmarksRtcstatsData(stateful: IStateful): boolean {
  89. const state = toState(stateful);
  90. const { faceLandmarks } = state['features/base/config'];
  91. if (faceLandmarks?.enableRTCStats && canSendRtcstatsData(state)) {
  92. return true;
  93. }
  94. return false;
  95. }