2021-09-14 15:31:30 +00:00
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { getParticipantById } from '../base/participants/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { editMessage } from '../chat/actions.any';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { MESSAGE_TYPE_REMOTE } from '../chat/constants';
|
2021-09-14 15:31:30 +00:00
|
|
|
|
|
|
|
import { UPDATE_BREAKOUT_ROOMS } from './actionTypes';
|
|
|
|
import { moveToRoom } from './actions';
|
|
|
|
import logger from './logger';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { IRooms } from './types';
|
2021-09-14 15:31:30 +00:00
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
declare const APP: any;
|
2022-05-20 10:45:09 +00:00
|
|
|
|
2021-09-14 15:31:30 +00:00
|
|
|
/**
|
|
|
|
* Registers a change handler for state['features/base/conference'].conference to
|
|
|
|
* set the event listeners needed for the breakout rooms feature to operate.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => state['features/base/conference'].conference,
|
|
|
|
(conference, { dispatch }, previousConference) => {
|
|
|
|
if (conference && !previousConference) {
|
2022-09-14 11:32:58 +00:00
|
|
|
conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, (roomId: string) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
logger.debug(`Moving to room: ${roomId}`);
|
|
|
|
dispatch(moveToRoom(roomId));
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ rooms, roomCounter }: {
|
|
|
|
roomCounter: number; rooms: IRooms;
|
|
|
|
}) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
logger.debug('Room list updated');
|
2022-05-20 10:45:09 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyBreakoutRoomsUpdated(rooms);
|
|
|
|
}
|
2021-09-14 15:31:30 +00:00
|
|
|
dispatch({
|
|
|
|
type: UPDATE_BREAKOUT_ROOMS,
|
2021-11-25 11:43:42 +00:00
|
|
|
rooms,
|
|
|
|
roomCounter
|
2021-09-14 15:31:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-12-22 16:55:08 +00:00
|
|
|
|
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
|
|
|
const { type } = action;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case UPDATE_BREAKOUT_ROOMS: {
|
2022-05-20 10:45:09 +00:00
|
|
|
// edit name if it was overwritten
|
|
|
|
if (!action.updatedNames) {
|
|
|
|
const { overwrittenNameList } = getState()['features/base/participants'];
|
|
|
|
|
|
|
|
if (Object.keys(overwrittenNameList).length > 0) {
|
2022-09-14 11:32:58 +00:00
|
|
|
const newRooms: IRooms = {};
|
2022-05-20 10:45:09 +00:00
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
Object.entries(action.rooms as IRooms).forEach(([ key, r ]) => {
|
2022-05-20 10:45:09 +00:00
|
|
|
let participants = r?.participants || {};
|
|
|
|
let jid;
|
|
|
|
|
|
|
|
for (const id of Object.keys(overwrittenNameList)) {
|
|
|
|
jid = Object.keys(participants).find(p => p.slice(p.indexOf('/') + 1) === id);
|
|
|
|
|
|
|
|
if (jid) {
|
|
|
|
participants = {
|
|
|
|
...participants,
|
|
|
|
[jid]: {
|
|
|
|
...participants[jid],
|
2022-09-14 11:32:58 +00:00
|
|
|
displayName: overwrittenNameList[id as keyof typeof overwrittenNameList]
|
2022-05-20 10:45:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newRooms[key] = {
|
|
|
|
...r,
|
|
|
|
participants
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
action.rooms = newRooms;
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 16:55:08 +00:00
|
|
|
|
|
|
|
// edit the chat history to match names for participants in breakout rooms
|
2022-05-20 10:45:09 +00:00
|
|
|
const { messages } = getState()['features/chat'];
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
messages?.forEach(m => {
|
2021-12-22 16:55:08 +00:00
|
|
|
if (m.messageType === MESSAGE_TYPE_REMOTE && !getParticipantById(getState(), m.id)) {
|
2022-09-14 11:32:58 +00:00
|
|
|
const rooms: IRooms = action.rooms;
|
2021-12-22 16:55:08 +00:00
|
|
|
|
|
|
|
for (const room of Object.values(rooms)) {
|
|
|
|
const participants = room.participants || {};
|
|
|
|
const matchedJid = Object.keys(participants).find(jid => jid.endsWith(m.id));
|
|
|
|
|
|
|
|
if (matchedJid) {
|
|
|
|
m.displayName = participants[matchedJid].displayName;
|
|
|
|
|
|
|
|
dispatch(editMessage(m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-20 10:45:09 +00:00
|
|
|
return next(action);
|
2021-12-22 16:55:08 +00:00
|
|
|
});
|