Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middleware.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import { getAmplitudeIdentity } from '../analytics';
  3. import { CONFERENCE_UNIQUE_ID_SET } from '../base/conference';
  4. import { LIB_WILL_INIT } from '../base/lib-jitsi-meet';
  5. import { getLocalParticipant } from '../base/participants';
  6. import { MiddlewareRegistry } from '../base/redux';
  7. import RTCStats from './RTCStats';
  8. import { isRtcstatsEnabled } from './functions';
  9. import logger from './logger';
  10. /**
  11. * Middleware which intercepts lib-jitsi-meet initialization and conference join in order init the
  12. * rtcstats-client.
  13. *
  14. * @param {Store} store - The redux store.
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. const state = store.getState();
  19. const config = state['features/base/config'];
  20. const { analytics } = config;
  21. switch (action.type) {
  22. case LIB_WILL_INIT: {
  23. if (isRtcstatsEnabled(state)) {
  24. // RTCStats "proxies" WebRTC functions such as GUM and RTCPeerConnection by rewriting the global
  25. // window functions. Because lib-jitsi-meet uses references to those functions that are taken on
  26. // init, we need to add these proxies before it initializes, otherwise lib-jitsi-meet will use the
  27. // original non proxy versions of these functions.
  28. try {
  29. // Default poll interval is 1000ms if not provided in the config.
  30. const pollInterval = analytics.rtcstatsPollInterval || 1000;
  31. // Initialize but don't connect to the rtcstats server wss, as it will start sending data for all
  32. // media calls made even before the conference started.
  33. RTCStats.init({
  34. rtcstatsEndpoint: analytics.rtcstatsEndpoint,
  35. rtcstatsPollInterval: pollInterval
  36. });
  37. } catch (error) {
  38. logger.error('Failed to initialize RTCStats: ', error);
  39. }
  40. }
  41. break;
  42. }
  43. case CONFERENCE_UNIQUE_ID_SET: {
  44. if (isRtcstatsEnabled(state) && RTCStats.isInitialized()) {
  45. // Once the conference started connect to the rtcstats server and send data.
  46. try {
  47. RTCStats.connect();
  48. const localParticipant = getLocalParticipant(state);
  49. // Unique identifier for a conference session, not to be confused with meeting name
  50. // i.e. If all participants leave a meeting it will have a different value on the next join.
  51. const { conference } = action;
  52. const meetingUniqueId = conference && conference.getMeetingUniqueId();
  53. // The current implementation of rtcstats-server is configured to send data to amplitude, thus
  54. // we add identity specific information so we can corelate 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. RTCStats.sendIdentityData({
  61. ...getAmplitudeIdentity(),
  62. ...config,
  63. displayName: localParticipant?.name,
  64. meetingUniqueId
  65. });
  66. } catch (error) {
  67. // If the connection failed do not impact jitsi-meet just silently fail.
  68. logger.error('RTCStats connect failed with: ', error);
  69. }
  70. }
  71. break;
  72. }
  73. }
  74. return next(action);
  75. });