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

middleware.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* @flow */
  2. import UIEvents from '../../../../service/UI/UIEvents';
  3. import {
  4. CONFERENCE_JOINED,
  5. CONFERENCE_LEFT
  6. } from '../conference';
  7. import { MiddlewareRegistry } from '../redux';
  8. import { localParticipantIdChanged } from './actions';
  9. import {
  10. KICK_PARTICIPANT,
  11. MUTE_REMOTE_PARTICIPANT,
  12. PARTICIPANT_DISPLAY_NAME_CHANGED,
  13. PARTICIPANT_JOINED,
  14. PARTICIPANT_UPDATED
  15. } from './actionTypes';
  16. import { LOCAL_PARTICIPANT_DEFAULT_ID } from './constants';
  17. import {
  18. getAvatarURLByParticipantId,
  19. getLocalParticipant
  20. } from './functions';
  21. declare var APP: Object;
  22. /**
  23. * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
  24. * updates respectively ID of local participant.
  25. *
  26. * @param {Store} store - Redux store.
  27. * @returns {Function}
  28. */
  29. MiddlewareRegistry.register(store => next => action => {
  30. const { conference } = store.getState()['features/base/conference'];
  31. switch (action.type) {
  32. case CONFERENCE_JOINED:
  33. store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
  34. break;
  35. case CONFERENCE_LEFT:
  36. store.dispatch(localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
  37. break;
  38. case KICK_PARTICIPANT:
  39. conference.kickParticipant(action.id);
  40. break;
  41. case MUTE_REMOTE_PARTICIPANT:
  42. conference.muteParticipant(action.id);
  43. break;
  44. // TODO Remove this middleware when the local display name update flow is
  45. // fully brought into redux.
  46. case PARTICIPANT_DISPLAY_NAME_CHANGED: {
  47. if (typeof APP !== 'undefined') {
  48. const participant = getLocalParticipant(store.getState());
  49. if (participant && participant.id === action.id) {
  50. APP.UI.emitEvent(UIEvents.NICKNAME_CHANGED, action.name);
  51. }
  52. }
  53. break;
  54. }
  55. case PARTICIPANT_JOINED:
  56. case PARTICIPANT_UPDATED: {
  57. if (typeof APP !== 'undefined') {
  58. const participant = action.participant;
  59. const { id, local } = participant;
  60. const preUpdateAvatarURL
  61. = getAvatarURLByParticipantId(store.getState(), id);
  62. // Allow the redux update to go through and compare the old avatar
  63. // to the new avatar and emit out change events if necessary.
  64. const result = next(action);
  65. const postUpdateAvatarURL
  66. = getAvatarURLByParticipantId(store.getState(), id);
  67. if (preUpdateAvatarURL !== postUpdateAvatarURL) {
  68. const currentKnownId = local
  69. ? APP.conference.getMyUserId() : id;
  70. APP.UI.refreshAvatarDisplay(
  71. currentKnownId, postUpdateAvatarURL);
  72. APP.API.notifyAvatarChanged(
  73. currentKnownId, postUpdateAvatarURL);
  74. }
  75. return result;
  76. }
  77. break;
  78. }
  79. }
  80. return next(action);
  81. });