2021-09-14 15:31:30 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
import { IStateful } from '../base/app/types';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { getCurrentConference } from '../base/conference/functions';
|
2022-11-02 17:06:45 +00:00
|
|
|
import { IJitsiConference } from '../base/conference/reducer';
|
|
|
|
import {
|
|
|
|
getLocalParticipant,
|
|
|
|
getParticipantById,
|
|
|
|
getParticipantCount,
|
|
|
|
isLocalParticipantModerator
|
|
|
|
} from '../base/participants/functions';
|
|
|
|
import { IJitsiParticipant } from '../base/participants/types';
|
2022-09-14 11:32:58 +00:00
|
|
|
import { toState } from '../base/redux/functions';
|
2021-09-14 15:31:30 +00:00
|
|
|
|
|
|
|
import { FEATURE_KEY } from './constants';
|
2022-11-02 17:06:45 +00:00
|
|
|
import { IRoom, IRoomInfo, IRoomInfoParticipant, IRooms, IRoomsInfo } from './types';
|
2021-09-14 15:31:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rooms object for breakout rooms.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2021-09-14 15:31:30 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {Object} Object of rooms.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getBreakoutRooms = (stateful: IStateful): IRooms => toState(stateful)[FEATURE_KEY].rooms;
|
2021-09-14 15:31:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the main room.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2021-09-14 15:31:30 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @returns {IRoom|undefined} The main room object, or undefined.
|
2021-09-14 15:31:30 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getMainRoom = (stateful: IStateful) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
const rooms = getBreakoutRooms(stateful);
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
return _.find(rooms, room => Boolean(room.isMainRoom));
|
2021-09-14 15:31:30 +00:00
|
|
|
};
|
|
|
|
|
2022-11-02 17:06:45 +00:00
|
|
|
/**
|
|
|
|
* Returns the rooms info.
|
|
|
|
*
|
|
|
|
* @param {IStateful} stateful - The redux store, the redux.
|
|
|
|
|
|
|
|
* @returns {IRoomsInfo} The rooms info.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getRoomsInfo = (stateful: IStateful) => {
|
2022-09-06 06:51:38 +00:00
|
|
|
const breakoutRooms = getBreakoutRooms(stateful);
|
2022-11-02 17:06:45 +00:00
|
|
|
const conference: IJitsiConference = getCurrentConference(stateful);
|
2022-09-06 06:51:38 +00:00
|
|
|
|
|
|
|
const initialRoomsInfo = {
|
|
|
|
rooms: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// only main roomn
|
|
|
|
if (!breakoutRooms || Object.keys(breakoutRooms).length === 0) {
|
2022-11-02 17:06:45 +00:00
|
|
|
// filter out hidden participants
|
|
|
|
const conferenceParticipants = conference?.getParticipants()
|
|
|
|
.filter((participant: IJitsiParticipant) => !participant.isHidden());
|
|
|
|
|
|
|
|
const localParticipant = getLocalParticipant(stateful);
|
|
|
|
let localParticipantInfo;
|
|
|
|
|
|
|
|
if (localParticipant) {
|
|
|
|
localParticipantInfo = {
|
|
|
|
role: localParticipant.role,
|
|
|
|
displayName: localParticipant.name,
|
|
|
|
avatarUrl: localParticipant.loadableAvatarUrl,
|
|
|
|
id: localParticipant.id
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-06 06:51:38 +00:00
|
|
|
return {
|
|
|
|
...initialRoomsInfo,
|
|
|
|
rooms: [ {
|
|
|
|
isMainRoom: true,
|
|
|
|
id: conference?.room?.roomjid,
|
|
|
|
jid: conference?.room?.myroomjid,
|
2022-11-02 17:06:45 +00:00
|
|
|
participants: conferenceParticipants?.length > 0
|
|
|
|
? [
|
|
|
|
localParticipantInfo,
|
|
|
|
...conferenceParticipants.map((participantItem: IJitsiParticipant) => {
|
|
|
|
const storeParticipant = getParticipantById(stateful, participantItem.getId());
|
|
|
|
|
|
|
|
return {
|
|
|
|
jid: participantItem.getJid(),
|
|
|
|
role: participantItem.getRole(),
|
|
|
|
displayName: participantItem.getDisplayName(),
|
|
|
|
avatarUrl: storeParticipant?.loadableAvatarUrl,
|
|
|
|
id: participantItem.getId()
|
|
|
|
} as IRoomInfoParticipant;
|
|
|
|
}) ]
|
|
|
|
: [ localParticipantInfo ]
|
|
|
|
} as IRoomInfo ]
|
|
|
|
} as IRoomsInfo;
|
2022-09-06 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...initialRoomsInfo,
|
|
|
|
rooms: Object.keys(breakoutRooms).map(breakoutRoomKey => {
|
|
|
|
const breakoutRoomItem = breakoutRooms[breakoutRoomKey];
|
|
|
|
|
|
|
|
return {
|
|
|
|
isMainRoom: Boolean(breakoutRoomItem.isMainRoom),
|
|
|
|
id: breakoutRoomItem.id,
|
|
|
|
jid: breakoutRoomItem.jid,
|
|
|
|
participants: breakoutRoomItem.participants && Object.keys(breakoutRoomItem.participants).length
|
|
|
|
? Object.keys(breakoutRoomItem.participants).map(participantLongId => {
|
|
|
|
const participantItem = breakoutRoomItem.participants[participantLongId];
|
|
|
|
const ids = participantLongId.split('/');
|
|
|
|
const storeParticipant = getParticipantById(stateful,
|
|
|
|
ids.length > 1 ? ids[1] : participantItem.jid);
|
|
|
|
|
|
|
|
return {
|
|
|
|
jid: participantItem?.jid,
|
|
|
|
role: participantItem?.role,
|
|
|
|
displayName: participantItem?.displayName,
|
|
|
|
avatarUrl: storeParticipant?.loadableAvatarUrl,
|
|
|
|
id: storeParticipant ? storeParticipant.id
|
|
|
|
: participantLongId
|
2022-11-02 17:06:45 +00:00
|
|
|
} as IRoomInfoParticipant;
|
2022-09-06 06:51:38 +00:00
|
|
|
}) : []
|
2022-11-02 17:06:45 +00:00
|
|
|
} as IRoomInfo;
|
2022-09-06 06:51:38 +00:00
|
|
|
})
|
2022-11-02 17:06:45 +00:00
|
|
|
} as IRoomsInfo;
|
2022-09-06 06:51:38 +00:00
|
|
|
};
|
|
|
|
|
2022-02-14 10:40:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the room by Jid.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2022-02-14 10:40:44 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @param {string} roomJid - The jid of the room.
|
2022-09-14 11:32:58 +00:00
|
|
|
* @returns {IRoom|undefined} The main room object, or undefined.
|
2022-02-14 10:40:44 +00:00
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getRoomByJid = (stateful: IStateful, roomJid: string) => {
|
2022-02-14 10:40:44 +00:00
|
|
|
const rooms = getBreakoutRooms(stateful);
|
|
|
|
|
2022-09-14 11:32:58 +00:00
|
|
|
return _.find(rooms, (room: IRoom) => room.jid === roomJid);
|
2022-02-14 10:40:44 +00:00
|
|
|
};
|
|
|
|
|
2021-09-14 15:31:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the id of the current room.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2021-09-14 15:31:30 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {string} Room id or undefined.
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getCurrentRoomId = (stateful: IStateful) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
const conference = getCurrentConference(stateful);
|
|
|
|
|
|
|
|
return conference?.getName();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the local participant is in a breakout room.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2021-09-14 15:31:30 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const isInBreakoutRoom = (stateful: IStateful) => {
|
2021-09-14 15:31:30 +00:00
|
|
|
const conference = getCurrentConference(stateful);
|
|
|
|
|
|
|
|
return conference?.getBreakoutRooms()
|
|
|
|
?.isBreakoutRoom();
|
|
|
|
};
|
2022-03-02 14:15:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the breakout rooms config.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, the redux
|
2022-03-02 14:15:18 +00:00
|
|
|
* {@code getState} function, or the redux state itself.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const getBreakoutRoomsConfig = (stateful: IStateful) => {
|
2022-03-02 14:15:18 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const { breakoutRooms = {} } = state['features/base/config'];
|
|
|
|
|
|
|
|
return breakoutRooms;
|
|
|
|
};
|
2022-04-29 09:30:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the add breakout room button is visible.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const isAddBreakoutRoomButtonVisible = (stateful: IStateful) => {
|
2022-04-29 09:30:49 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const isLocalModerator = isLocalParticipantModerator(state);
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const isBreakoutRoomsSupported = conference?.getBreakoutRooms()?.isSupported();
|
|
|
|
const { hideAddRoomButton } = getBreakoutRoomsConfig(state);
|
|
|
|
|
|
|
|
return isLocalModerator && isBreakoutRoomsSupported && !hideAddRoomButton;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the auto assign participants to breakout rooms button is visible.
|
|
|
|
*
|
2022-09-14 11:32:58 +00:00
|
|
|
* @param {IStateful} stateful - Global state.
|
2022-04-29 09:30:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-14 11:32:58 +00:00
|
|
|
export const isAutoAssignParticipantsVisible = (stateful: IStateful) => {
|
2022-04-29 09:30:49 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
const rooms = getBreakoutRooms(state);
|
|
|
|
const inBreakoutRoom = isInBreakoutRoom(state);
|
|
|
|
const isLocalModerator = isLocalParticipantModerator(state);
|
|
|
|
const participantsCount = getParticipantCount(state);
|
|
|
|
const { hideAutoAssignButton } = getBreakoutRoomsConfig(state);
|
|
|
|
|
|
|
|
return !inBreakoutRoom
|
|
|
|
&& isLocalModerator
|
|
|
|
&& participantsCount > 2
|
|
|
|
&& Object.keys(rooms).length > 1
|
|
|
|
&& !hideAutoAssignButton;
|
|
|
|
};
|