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

middleware.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
  3. import { CONFERENCE_JOINED } from '../base/conference';
  4. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  5. import { MiddlewareRegistry } from '../base/redux';
  6. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  7. import { INCOMING_MSG_SOUND_ID } from './constants';
  8. import { INCOMING_MSG_SOUND_SRC } from './sounds';
  9. declare var APP: Object;
  10. /**
  11. * Implements the middleware of the chat feature.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. switch (action.type) {
  18. case APP_WILL_MOUNT: {
  19. // Register chat msg sound only on web
  20. typeof APP !== 'undefined'
  21. && store.dispatch(
  22. registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
  23. break;
  24. }
  25. case APP_WILL_UNMOUNT: {
  26. // Register chat msg sound only on web
  27. typeof APP !== 'undefined'
  28. && store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
  29. break;
  30. }
  31. case CONFERENCE_JOINED:
  32. typeof APP !== 'undefined'
  33. && _addChatMsgListener(action.conference, store);
  34. break;
  35. }
  36. return next(action);
  37. });
  38. /**
  39. * Registers listener for {@link JitsiConferenceEvents.MESSAGE_RECEIVED} which
  40. * will play a sound on the event, given that the chat is not currently visible.
  41. *
  42. * @param {JitsiConference} conference - The conference instance on which the
  43. * new event listener will be registered.
  44. * @param {Dispatch} next - The redux dispatch function to dispatch the
  45. * specified action to the specified store.
  46. * @returns {void}
  47. * @private
  48. */
  49. function _addChatMsgListener(conference, { dispatch }) {
  50. // XXX Currently there's no need to remove the listener, because
  51. // conference instance can not be re-used. Listener will be gone with
  52. // the conference instance.
  53. conference.on(
  54. JitsiConferenceEvents.MESSAGE_RECEIVED,
  55. () => {
  56. if (!APP.UI.isChatVisible()) {
  57. dispatch(playSound(INCOMING_MSG_SOUND_ID));
  58. }
  59. });
  60. }