2021-09-14 15:31:30 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2021-12-22 16:55:08 +00:00
|
|
|
import { getParticipantById } from '../base/participants';
|
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
|
|
|
import { editMessage, MESSAGE_TYPE_REMOTE } from '../chat';
|
2021-09-14 15:31:30 +00:00
|
|
|
|
|
|
|
import { UPDATE_BREAKOUT_ROOMS } from './actionTypes';
|
|
|
|
import { moveToRoom } from './actions';
|
2021-12-22 16:55:08 +00:00
|
|
|
import { getBreakoutRooms } from './functions';
|
2021-09-14 15:31:30 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM, roomId => {
|
|
|
|
logger.debug(`Moving to room: ${roomId}`);
|
|
|
|
dispatch(moveToRoom(roomId));
|
|
|
|
});
|
|
|
|
|
2021-11-25 11:43:42 +00:00
|
|
|
conference.on(JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED, ({ rooms, roomCounter }) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
logger.debug('Room list updated');
|
|
|
|
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;
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case UPDATE_BREAKOUT_ROOMS: {
|
|
|
|
const { messages } = getState()['features/chat'];
|
|
|
|
|
|
|
|
// edit the chat history to match names for participants in breakout rooms
|
|
|
|
messages && messages.forEach(m => {
|
|
|
|
if (m.messageType === MESSAGE_TYPE_REMOTE && !getParticipantById(getState(), m.id)) {
|
|
|
|
const rooms = getBreakoutRooms(getState);
|
|
|
|
|
|
|
|
for (const room of Object.values(rooms)) {
|
|
|
|
// $FlowExpectedError
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|