You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {
  2. LIB_DISPOSED,
  3. LIB_INITIALIZED
  4. } from '../lib-jitsi-meet';
  5. import {
  6. AUDIO_MUTED_CHANGED,
  7. CAMERA_FACING_MODE_CHANGED,
  8. MEDIA_TYPE,
  9. VIDEO_MUTED_CHANGED
  10. } from '../media';
  11. import { MiddlewareRegistry } from '../redux';
  12. import {
  13. createLocalTracks,
  14. destroyLocalTracks
  15. } from './actions';
  16. import {
  17. getLocalTrack,
  18. setTrackMuted
  19. } from './functions';
  20. /**
  21. * Middleware that captures LIB_INITIALIZED and LIB_DISPOSED actions
  22. * and respectively creates/destroys local media tracks. Also listens to media-
  23. * related actions and performs corresponding operations with tracks.
  24. *
  25. * @param {Store} store - Redux store.
  26. * @returns {Function}
  27. */
  28. MiddlewareRegistry.register(store => next => action => {
  29. switch (action.type) {
  30. case AUDIO_MUTED_CHANGED:
  31. _mutedChanged(store, action, MEDIA_TYPE.AUDIO);
  32. break;
  33. case CAMERA_FACING_MODE_CHANGED:
  34. store.dispatch(
  35. createLocalTracks({
  36. devices: [ MEDIA_TYPE.VIDEO ],
  37. facingMode: action.cameraFacingMode
  38. })
  39. );
  40. break;
  41. case LIB_INITIALIZED:
  42. store.dispatch(createLocalTracks());
  43. break;
  44. case LIB_DISPOSED:
  45. store.dispatch(destroyLocalTracks());
  46. break;
  47. case VIDEO_MUTED_CHANGED:
  48. _mutedChanged(store, action, MEDIA_TYPE.VIDEO);
  49. break;
  50. }
  51. return next(action);
  52. });
  53. /**
  54. * Mutes or unmutes a local track with a specific media type.
  55. *
  56. * @param {Store} store - The Redux store in which the specified action is
  57. * dispatched.
  58. * @param {Action} action - The Redux action dispatched in the specified store.
  59. * @param {MEDIA_TYPE} mediaType - The {@link MEDIA_TYPE} of the local track
  60. * which is being muted or unmuted.
  61. * @private
  62. * @returns {void}
  63. */
  64. function _mutedChanged(store, action, mediaType) {
  65. const tracks = store.getState()['features/base/tracks'];
  66. const localTrack = getLocalTrack(tracks, mediaType);
  67. localTrack && setTrackMuted(localTrack.jitsiTrack, action.muted);
  68. }