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.

functions.ts 4.0KB

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