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

middleware.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @flow
  2. import {
  3. ADD_PREJOIN_AUDIO_TRACK,
  4. ADD_PREJOIN_VIDEO_TRACK,
  5. PREJOIN_START_CONFERENCE
  6. } from './actionTypes';
  7. import { setPrejoinAudioMuted, setPrejoinVideoMuted } from './actions';
  8. import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../base/media';
  9. import { participantUpdated, getLocalParticipant } from '../base/participants';
  10. import { MiddlewareRegistry } from '../base/redux';
  11. import { updateSettings } from '../base/settings';
  12. import { getAllPrejoinConfiguredTracks, getPrejoinName } from './functions';
  13. declare var APP: Object;
  14. /**
  15. * The redux middleware for {@link PrejoinPage}.
  16. *
  17. * @param {Store} store - The redux store.
  18. * @returns {Function}
  19. */
  20. MiddlewareRegistry.register(store => next => async action => {
  21. switch (action.type) {
  22. case ADD_PREJOIN_AUDIO_TRACK: {
  23. const { value: audioTrack } = action;
  24. if (audioTrack) {
  25. store.dispatch(
  26. updateSettings({
  27. micDeviceId: audioTrack.getDeviceId()
  28. }),
  29. );
  30. }
  31. break;
  32. }
  33. case ADD_PREJOIN_VIDEO_TRACK: {
  34. const { value: videoTrack } = action;
  35. if (videoTrack) {
  36. store.dispatch(
  37. updateSettings({
  38. cameraDeviceId: videoTrack.getDeviceId()
  39. }),
  40. );
  41. }
  42. break;
  43. }
  44. case PREJOIN_START_CONFERENCE: {
  45. const { dispatch, getState } = store;
  46. _syncParticipantName(dispatch, getState);
  47. const tracks = await getAllPrejoinConfiguredTracks(getState());
  48. APP.conference.prejoinStart(tracks);
  49. break;
  50. }
  51. case SET_AUDIO_MUTED: {
  52. store.dispatch(setPrejoinAudioMuted(Boolean(action.muted)));
  53. break;
  54. }
  55. case SET_VIDEO_MUTED: {
  56. store.dispatch(setPrejoinVideoMuted(Boolean(action.muted)));
  57. break;
  58. }
  59. }
  60. return next(action);
  61. });
  62. /**
  63. * Sets the local participant name if one is present.
  64. *
  65. * @param {Function} dispatch - The redux dispatch function.
  66. * @param {Function} getState - Gets the current state.
  67. * @returns {undefined}
  68. */
  69. function _syncParticipantName(dispatch, getState) {
  70. const state = getState();
  71. const name = getPrejoinName(state);
  72. name && dispatch(
  73. participantUpdated({
  74. ...getLocalParticipant(state),
  75. name
  76. }),
  77. );
  78. }