Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/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_FILE } 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 the chat message sound on Web only because there's no chat
  20. // on mobile.
  21. typeof APP === 'undefined'
  22. || store.dispatch(
  23. registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));
  24. break;
  25. case APP_WILL_UNMOUNT:
  26. // Unregister the chat message sound on Web because it's registered
  27. // there only.
  28. typeof APP === 'undefined'
  29. || store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
  30. break;
  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. * @private
  47. * @returns {void}
  48. */
  49. function _addChatMsgListener(conference, { dispatch }) {
  50. // XXX Currently, there's no need to remove the listener, because the
  51. // JitsiConference instance cannot be reused. Hence, the listener will be
  52. // gone with the JitsiConference instance.
  53. conference.on(
  54. JitsiConferenceEvents.MESSAGE_RECEIVED,
  55. () => {
  56. APP.UI.isChatVisible()
  57. || dispatch(playSound(INCOMING_MSG_SOUND_ID));
  58. });
  59. }