"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7555/react/features/breakout-rooms/middleware.ts" (28 Sep 2023, 3962 Bytes) of package /linux/misc/jitsi-meet-7555.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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