2022-09-30 14:50:45 +00:00
|
|
|
import md5 from 'js-md5';
|
|
|
|
|
2022-10-11 10:47:54 +00:00
|
|
|
import { getPinnedParticipant } from '../../features/base/participants/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../app/types';
|
2022-09-30 14:50:45 +00:00
|
|
|
import { getCurrentConference } from '../base/conference/functions';
|
|
|
|
import { getRemoteParticipants, isLocalParticipantModerator } from '../base/participants/functions';
|
|
|
|
import { appendURLParam } from '../base/util/uri';
|
|
|
|
import { getCurrentRoomId, isInBreakoutRoom } from '../breakout-rooms/functions';
|
|
|
|
|
|
|
|
import { WHITEBOARD_ID } from './constants';
|
|
|
|
import { IWhiteboardState } from './reducer';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
const getWhiteboardState = (state: IReduxState): IWhiteboardState => state['features/whiteboard'];
|
2022-09-30 14:50:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the whiteboard is enabled in the config.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isWhiteboardEnabled = (state: IReduxState): boolean =>
|
2022-09-30 14:50:45 +00:00
|
|
|
state['features/base/config'].whiteboard?.enabled
|
|
|
|
&& state['features/base/config'].whiteboard?.collabServerBaseUrl
|
|
|
|
&& getCurrentConference(state)?.getMetadataHandler()
|
|
|
|
?.isSupported();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the whiteboard is open.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isWhiteboardOpen = (state: IReduxState): boolean => getWhiteboardState(state).isOpen;
|
2022-09-30 14:50:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the whiteboard button is visible.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isWhiteboardButtonVisible = (state: IReduxState): boolean =>
|
2022-09-30 14:50:45 +00:00
|
|
|
isWhiteboardEnabled(state) && (isLocalParticipantModerator(state) || isWhiteboardOpen(state));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the whiteboard is present as a meeting participant.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isWhiteboardPresent = (state: IReduxState): boolean => getRemoteParticipants(state).has(WHITEBOARD_ID);
|
2022-09-30 14:50:45 +00:00
|
|
|
|
|
|
|
/**
|
2022-10-06 12:22:48 +00:00
|
|
|
* Returns the whiteboard collaboration details.
|
2022-09-30 14:50:45 +00:00
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-10-06 12:22:48 +00:00
|
|
|
* @returns {{ roomId: string, roomKey: string}|undefined}
|
2022-09-30 14:50:45 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const getCollabDetails = (state: IReduxState): {
|
2022-09-30 14:50:45 +00:00
|
|
|
roomId: string; roomKey: string;
|
|
|
|
} | undefined => getWhiteboardState(state).collabDetails;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the whiteboard collaboration server url.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const getCollabServerUrl = (state: IReduxState): string | undefined => {
|
2022-09-30 14:50:45 +00:00
|
|
|
const collabServerBaseUrl = state['features/base/config'].whiteboard?.collabServerBaseUrl;
|
|
|
|
|
|
|
|
if (!collabServerBaseUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { locationURL } = state['features/base/connection'];
|
|
|
|
const inBreakoutRoom = isInBreakoutRoom(state);
|
|
|
|
const roomId = getCurrentRoomId(state);
|
|
|
|
const room = md5.hex(`${locationURL?.href}${inBreakoutRoom ? `|${roomId}` : ''}`);
|
|
|
|
|
|
|
|
return appendURLParam(collabServerBaseUrl, 'room', room);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the whiteboard is visible on stage.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state from the Redux store.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export const isWhiteboardVisible = (state: IReduxState): boolean =>
|
2022-09-30 14:50:45 +00:00
|
|
|
getPinnedParticipant(state)?.id === WHITEBOARD_ID
|
|
|
|
|| state['features/large-video'].participantId === WHITEBOARD_ID;
|