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.

functions.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* eslint-disable import/order */
  2. // @ts-ignore
  3. import { jitsiLocalStorage } from '@jitsi/js-utils';
  4. import { getAmplitudeIdentity } from '../analytics/functions';
  5. import {
  6. getConferenceOptions,
  7. getAnalyticsRoomName
  8. // @ts-ignore
  9. } from '../base/conference';
  10. // @ts-ignore
  11. import { getLocalParticipant } from '../base/participants';
  12. // @ts-ignore
  13. import { toState } from '../base/redux';
  14. import RTCStats from './RTCStats';
  15. import logger from './logger';
  16. /**
  17. * Checks whether rtcstats is enabled or not.
  18. *
  19. * @param {Function|Object} stateful - The redux store or {@code getState} function.
  20. * @returns {boolean}
  21. */
  22. export function isRtcstatsEnabled(stateful: Function | Object) {
  23. const state = toState(stateful);
  24. const config = state['features/base/config'];
  25. return config?.analytics?.rtcstatsEnabled ?? false;
  26. }
  27. /**
  28. * Can the rtcstats service send data.
  29. *
  30. * @param {Function|Object} stateful - The redux store or {@code getState} function.
  31. * @returns {boolean}
  32. */
  33. export function canSendRtcstatsData(stateful: Function | Object) {
  34. return isRtcstatsEnabled(stateful) && RTCStats.isInitialized();
  35. }
  36. type Identity = {
  37. isBreakoutRoom: boolean;
  38. // Unique identifier for a conference session, not to be confused with meeting name
  39. // i.e. If all participants leave a meeting it will have a different value on the next join.
  40. meetingUniqueId?: string;
  41. roomId?: string;
  42. };
  43. /**
  44. * Connects to the rtcstats service and sends the identity data.
  45. *
  46. * @param {Function} dispatch - The redux dispatch function.
  47. * @param {Function|Object} stateful - The redux store or {@code getState} function.
  48. * @param {Identity} identity - Identity data for the client.
  49. * @returns {void}
  50. */
  51. export function connectAndSendIdentity(dispatch: Function, stateful: Function | Object, identity: Identity) {
  52. const state = toState(stateful);
  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. }