You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // @flow
  2. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  3. import { getParticipantById } from '../base/participants';
  4. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  5. import { editMessage, MESSAGE_TYPE_REMOTE } from '../chat';
  6. import { UPDATE_BREAKOUT_ROOMS } from './actionTypes';
  7. import { moveToRoom } from './actions';
  8. import logger from './logger';
  9. declare var APP: Object;
  10. /**
  11. * Registers a change handler for state['features/base/conference'].conference to
  12. * set the event listeners needed for the breakout rooms feature to operate.
  13. */
  14. StateListenerRegistry.register(
  15. state => state['features/base/conference'].conference,
  16. (conference, { dispatch }, previousConference) => {
  17. if (conference && !previousConference) {
  18. conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, roomId => {
  19. logger.debug(`Moving to room: ${roomId}`);
  20. dispatch(moveToRoom(roomId));
  21. });
  22. conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ rooms, roomCounter }) => {
  23. logger.debug('Room list updated');
  24. if (typeof APP !== 'undefined') {
  25. APP.API.notifyBreakoutRoomsUpdated(rooms);
  26. }
  27. dispatch({
  28. type: UPDATE_BREAKOUT_ROOMS,
  29. rooms,
  30. roomCounter
  31. });
  32. });
  33. }
  34. });
  35. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  36. const { type } = action;
  37. switch (type) {
  38. case UPDATE_BREAKOUT_ROOMS: {
  39. // edit name if it was overwritten
  40. if (!action.updatedNames) {
  41. const { overwrittenNameList } = getState()['features/base/participants'];
  42. if (Object.keys(overwrittenNameList).length > 0) {
  43. const newRooms = {};
  44. Object.entries(action.rooms).forEach(([ key, r ]) => {
  45. let participants = r?.participants || {};
  46. let jid;
  47. for (const id of Object.keys(overwrittenNameList)) {
  48. jid = Object.keys(participants).find(p => p.slice(p.indexOf('/') + 1) === id);
  49. if (jid) {
  50. participants = {
  51. ...participants,
  52. [jid]: {
  53. ...participants[jid],
  54. displayName: overwrittenNameList[id]
  55. }
  56. };
  57. }
  58. }
  59. newRooms[key] = {
  60. ...r,
  61. participants
  62. };
  63. });
  64. action.rooms = newRooms;
  65. }
  66. }
  67. // edit the chat history to match names for participants in breakout rooms
  68. const { messages } = getState()['features/chat'];
  69. messages && messages.forEach(m => {
  70. if (m.messageType === MESSAGE_TYPE_REMOTE && !getParticipantById(getState(), m.id)) {
  71. const rooms = action.rooms;
  72. for (const room of Object.values(rooms)) {
  73. // $FlowExpectedError
  74. const participants = room.participants || {};
  75. const matchedJid = Object.keys(participants).find(jid => jid.endsWith(m.id));
  76. if (matchedJid) {
  77. m.displayName = participants[matchedJid].displayName;
  78. dispatch(editMessage(m));
  79. }
  80. }
  81. }
  82. });
  83. break;
  84. }
  85. }
  86. return next(action);
  87. });