Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* @flow */
  2. import { sendAnalyticsEvent } from '../../analytics';
  3. import { SET_ROOM, setAudioOnly } from '../conference';
  4. import { parseURLParams } from '../config';
  5. import { MiddlewareRegistry } from '../redux';
  6. import { setTrackMuted, TRACK_ADDED } from '../tracks';
  7. import { setAudioMuted, setCameraFacingMode, setVideoMuted } from './actions';
  8. import { CAMERA_FACING_MODE } from './constants';
  9. const logger = require('jitsi-meet-logger').getLogger(__filename);
  10. /**
  11. * Implements the entry point of the middleware of the feature base/media.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. switch (action.type) {
  18. case SET_ROOM:
  19. return _setRoom(store, next, action);
  20. case TRACK_ADDED: {
  21. const result = next(action);
  22. action.track.local && _syncTrackMutedState(store, action.track);
  23. return result;
  24. }
  25. }
  26. return next(action);
  27. });
  28. /**
  29. * Notifies the feature base/media that the action {@link SET_ROOM} is being
  30. * dispatched within a specific redux {@code store}.
  31. *
  32. * @param {Store} store - The redux store in which the specified {@code action}
  33. * is being dispatched.
  34. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  35. * specified {@code action} to the specified {@code store}.
  36. * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
  37. * dispatched in the specified {@code store}.
  38. * @private
  39. * @returns {Object} The new state that is the result of the reduction of the
  40. * specified {@code action}.
  41. */
  42. function _setRoom({ dispatch, getState }, next, action) {
  43. const { room } = action;
  44. // Read the config.
  45. const state = getState();
  46. let urlParams;
  47. let audioMuted;
  48. let videoMuted;
  49. if (room) {
  50. // The Jitsi Meet client may override the Jitsi Meet deployment in the
  51. // (location) URL on the subject of the following:
  52. // - startAudioOnly
  53. // - startWithAudioMuted
  54. // - startWithVideoMuted
  55. urlParams
  56. = parseURLParams(state['features/base/connection'].locationURL);
  57. audioMuted = urlParams['config.startWithAudioMuted'];
  58. videoMuted = urlParams['config.startWithVideoMuted'];
  59. }
  60. // Of course, the Jitsi Meet deployment defines config.js which should be
  61. // respected if the client did not override it.
  62. const config = state['features/base/config'];
  63. typeof audioMuted === 'undefined'
  64. && (audioMuted = config.startWithAudioMuted);
  65. typeof videoMuted === 'undefined'
  66. && (videoMuted = config.startWithVideoMuted);
  67. audioMuted = Boolean(audioMuted);
  68. videoMuted = Boolean(videoMuted);
  69. // Apply the config.
  70. sendAnalyticsEvent(
  71. `startmuted.client.audio.${audioMuted ? 'muted' : 'unmuted'}`);
  72. sendAnalyticsEvent(
  73. `startmuted.client.video.${videoMuted ? 'muted' : 'unmuted'}`);
  74. logger.log(`Start muted: ${audioMuted ? 'audio, ' : ''}${
  75. videoMuted ? 'video' : ''}`);
  76. // Unconditionally express the desires/expectations/intents of the app and
  77. // the user i.e. the state of base/media. Eventually, practice/reality i.e.
  78. // the state of base/tracks will or will not agree with the desires.
  79. dispatch(setAudioMuted(audioMuted));
  80. dispatch(setCameraFacingMode(CAMERA_FACING_MODE.USER));
  81. dispatch(setVideoMuted(videoMuted));
  82. // config.startAudioOnly
  83. //
  84. // FIXME Technically, the audio-only feature is owned by base/conference,
  85. // not base/media so the following should be in base/conference.
  86. // Practically, I presume it was easier to write the source code here
  87. // because it looks like config.startWithAudioMuted and
  88. // config.startWithVideoMuted.
  89. if (room) {
  90. let audioOnly = urlParams && urlParams['config.startAudioOnly'];
  91. typeof audioOnly === 'undefined' && (audioOnly = config.startAudioOnly);
  92. audioOnly = Boolean(audioOnly);
  93. sendAnalyticsEvent(
  94. `startaudioonly.${audioOnly ? 'enabled' : 'disabled'}`);
  95. logger.log(`Start audio only set to ${audioOnly.toString()}`);
  96. dispatch(setAudioOnly(audioOnly));
  97. }
  98. return next(action);
  99. }
  100. /**
  101. * Syncs muted state of local media track with muted state from media state.
  102. *
  103. * @param {Store} store - The redux store.
  104. * @param {Track} track - The local media track.
  105. * @private
  106. * @returns {void}
  107. */
  108. function _syncTrackMutedState({ getState }, track) {
  109. const state = getState()['features/base/media'];
  110. const muted = Boolean(state[track.mediaType].muted);
  111. // XXX If muted state of track when it was added is different from our media
  112. // muted state, we need to mute track and explicitly modify 'muted' property
  113. // on track. This is because though TRACK_ADDED action was dispatched it's
  114. // not yet in redux state and JitsiTrackEvents.TRACK_MUTE_CHANGED may be
  115. // fired before track gets to state.
  116. if (track.muted !== muted) {
  117. sendAnalyticsEvent(
  118. `synctrackstate.${track.mediaType}.${muted ? 'muted' : 'unmuted'}`);
  119. logger.log(`Sync ${track.mediaType} track muted state to ${
  120. muted ? 'muted' : 'unmuted'}`);
  121. track.muted = muted;
  122. setTrackMuted(track.jitsiTrack, muted);
  123. }
  124. }