Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { PARTICIPANT_ID_CHANGED } from '../participants';
  2. import { ReducerRegistry } from '../redux';
  3. import {
  4. TRACK_ADDED,
  5. TRACK_REMOVED,
  6. TRACK_UPDATED
  7. } from './actionTypes';
  8. /**
  9. * @typedef {Object} Track
  10. * @property {(JitsiLocalTrack|JitsiRemoteTrack)} jitsiTrack - JitsiTrack
  11. * instance.
  12. * @property {boolean} local=false - If track is local.
  13. * @property {MEDIA_TYPE} mediaType=false - Media type of track.
  14. * @property {boolean} mirrorVideo=false - If video track should be mirrored.
  15. * @property {boolean} muted=false - If track is muted.
  16. * @property {(string|undefined)} participantId - ID of participant whom this
  17. * track belongs to.
  18. * @property {boolean} videoStarted=false - If video track has already started
  19. * to play.
  20. * @property {(VIDEO_TYPE|undefined)} videoType - Type of video track if any.
  21. */
  22. /**
  23. * Reducer function for a single track.
  24. *
  25. * @param {Track|undefined} state - Track to be modified.
  26. * @param {Object} action - Action object.
  27. * @param {string} action.type - Type of action.
  28. * @param {string} action.newValue - New participant ID value (in this
  29. * particular case).
  30. * @param {string} action.oldValue - Old participant ID value (in this
  31. * particular case).
  32. * @param {Track} action.track - Information about track to be changed.
  33. * @param {Participant} action.participant - Information about participant.
  34. * @returns {Track|undefined}
  35. */
  36. function track(state, action) {
  37. switch (action.type) {
  38. case PARTICIPANT_ID_CHANGED:
  39. if (state.participantId === action.oldValue) {
  40. return {
  41. ...state,
  42. participantId: action.newValue
  43. };
  44. }
  45. break;
  46. case TRACK_UPDATED: {
  47. const t = action.track;
  48. if (state.jitsiTrack === t.jitsiTrack) {
  49. // Make sure that there's an actual update in order to reduce the
  50. // risk of unnecessary React Component renders.
  51. for (const p in t) {
  52. if (state[p] !== t[p]) {
  53. // There's an actual update.
  54. return {
  55. ...state,
  56. ...t
  57. };
  58. }
  59. }
  60. }
  61. break;
  62. }
  63. }
  64. return state;
  65. }
  66. /**
  67. * Listen for actions that mutate (e.g. add, remove) local and remote tracks.
  68. */
  69. ReducerRegistry.register('features/base/tracks', (state = [], action) => {
  70. switch (action.type) {
  71. case PARTICIPANT_ID_CHANGED:
  72. case TRACK_UPDATED:
  73. return state.map(t => track(t, action));
  74. case TRACK_ADDED:
  75. return [
  76. ...state,
  77. action.track
  78. ];
  79. case TRACK_REMOVED:
  80. return state.filter(t => t.jitsiTrack !== action.track.jitsiTrack);
  81. default:
  82. return state;
  83. }
  84. });