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

middleware.js 3.3KB

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