您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 3.3KB

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