mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2026-05-22 17:17:48 +00:00
90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import { createOpenWhiteboardEvent } from '../analytics/AnalyticsEvents';
|
|
import { sendAnalytics } from '../analytics/functions';
|
|
import { IStore } from '../app/types';
|
|
import { getCurrentConference } from '../base/conference/functions';
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
|
|
|
import { SET_WHITEBOARD_OPEN } from './actionTypes';
|
|
import {
|
|
notifyWhiteboardLimit,
|
|
resetWhiteboard,
|
|
restrictWhiteboard,
|
|
setWhiteboardOpen,
|
|
setupWhiteboard
|
|
} from './actions';
|
|
import { WHITEBOARD_ID } from './constants';
|
|
import {
|
|
isWhiteboardOpen,
|
|
shouldEnforceUserLimit,
|
|
shouldNotifyUserLimit
|
|
} from './functions';
|
|
|
|
MiddlewareRegistry.register((store: IStore) => next => action => {
|
|
const state = store.getState();
|
|
|
|
switch (action.type) {
|
|
case SET_WHITEBOARD_OPEN: {
|
|
const enforceUserLimit = shouldEnforceUserLimit(state);
|
|
const notifyUserLimit = shouldNotifyUserLimit(state);
|
|
|
|
if (action.isOpen && !enforceUserLimit && !notifyUserLimit) {
|
|
sendAnalytics(createOpenWhiteboardEvent());
|
|
|
|
return next(action);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return next(action);
|
|
});
|
|
|
|
/**
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
|
* is left or failed, e.g. Disable the whiteboard if it's left open.
|
|
*/
|
|
StateListenerRegistry.register(
|
|
state => getCurrentConference(state),
|
|
(conference, { dispatch }, previousConference): void => {
|
|
if (conference !== previousConference) {
|
|
dispatch(resetWhiteboard());
|
|
}
|
|
if (conference && !previousConference) {
|
|
conference.on(JitsiConferenceEvents.METADATA_UPDATED, (metadata: any) => {
|
|
if (metadata[WHITEBOARD_ID]) {
|
|
dispatch(setupWhiteboard({
|
|
collabDetails: metadata[WHITEBOARD_ID].collabDetails
|
|
}));
|
|
dispatch(setWhiteboardOpen(true));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Set up state change listener to limit whiteboard access.
|
|
*/
|
|
StateListenerRegistry.register(
|
|
state => shouldEnforceUserLimit(state),
|
|
(enforceUserLimit, { dispatch, getState }): void => {
|
|
if (isWhiteboardOpen(getState()) && enforceUserLimit) {
|
|
dispatch(restrictWhiteboard());
|
|
}
|
|
}
|
|
);
|
|
|
|
/**
|
|
* Set up state change listener to notify about whiteboard usage.
|
|
*/
|
|
StateListenerRegistry.register(
|
|
state => shouldNotifyUserLimit(state),
|
|
(notifyUserLimit, { dispatch, getState }, prevNotifyUserLimit): void => {
|
|
if (isWhiteboardOpen(getState()) && notifyUserLimit && !prevNotifyUserLimit) {
|
|
dispatch(notifyWhiteboardLimit());
|
|
}
|
|
}
|
|
);
|