Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

middleware.ts 3.9KB

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