bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/whiteboard-toolbar/service.js

126 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-06-08 04:45:49 +08:00
import { makeCall } from '/imports/ui/services/api';
import Storage from '/imports/ui/services/storage/session';
import Users from '/imports/ui/local-collections/users-collection/users';
import Auth from '/imports/ui/services/auth';
import getFromUserSettings from '/imports/ui/services/users-settings';
2017-04-20 02:27:00 +08:00
2017-09-21 05:05:17 +08:00
const DRAW_SETTINGS = 'drawSettings';
const PALM_REJECTION_MODE = 'palmRejectionMode';
const WHITEBOARD_TOOLBAR = Meteor.settings.public.whiteboard.toolbar;
2017-09-21 05:05:17 +08:00
const makeSetter = key => (value) => {
const drawSettings = Storage.getItem(DRAW_SETTINGS);
if (drawSettings) {
drawSettings[key] = value;
Storage.setItem(DRAW_SETTINGS, drawSettings);
}
};
2017-09-22 08:18:15 +08:00
const undoAnnotation = (whiteboardId) => {
makeCall('undoAnnotation', whiteboardId);
};
2017-09-22 08:18:15 +08:00
const clearWhiteboard = (whiteboardId) => {
makeCall('clearWhiteboard', whiteboardId);
};
const changeWhiteboardMode = (multiUser, whiteboardId) => {
makeCall('changeWhiteboardAccess', multiUser, whiteboardId);
};
const getCurrentPalmRejectionMode = () => Storage.getItem(PALM_REJECTION_MODE);
const setInitialPalmRejectionMode = (palmRejectionMode) => {
const _palmRejectionMode = Storage.getItem(PALM_REJECTION_MODE);
if (!_palmRejectionMode) {
Storage.setItem(PALM_REJECTION_MODE, palmRejectionMode);
}
};
const setPalmRejectionMode = (palmRejectionMode) => {
Storage.setItem(PALM_REJECTION_MODE, palmRejectionMode);
};
2017-09-22 08:18:15 +08:00
const setInitialWhiteboardToolbarValues = (tool, thickness, color, fontSize, textShape) => {
const _drawSettings = Storage.getItem(DRAW_SETTINGS);
if (!_drawSettings) {
const drawSettings = {
whiteboardAnnotationTool: tool,
whiteboardAnnotationThickness: thickness,
whiteboardAnnotationColor: color,
textFontSize: fontSize,
textShape,
};
Storage.setItem(DRAW_SETTINGS, drawSettings);
}
};
2017-09-22 08:18:15 +08:00
const getCurrentDrawSettings = () => Storage.getItem(DRAW_SETTINGS);
2017-09-22 08:18:15 +08:00
const setFontSize = makeSetter('textFontSize');
2017-09-22 08:18:15 +08:00
const setTool = makeSetter('whiteboardAnnotationTool');
2017-09-22 08:18:15 +08:00
const setThickness = makeSetter('whiteboardAnnotationThickness');
2017-09-22 08:18:15 +08:00
const setColor = makeSetter('whiteboardAnnotationColor');
2017-09-22 08:18:15 +08:00
const setTextShapeObject = makeSetter('textShape');
2017-04-20 02:27:00 +08:00
const getTextShapeActiveId = () => {
2017-09-21 05:05:17 +08:00
const drawSettings = Storage.getItem(DRAW_SETTINGS);
return drawSettings ? drawSettings.textShape.textShapeActiveId : '';
};
const isPresenter = () => {
const currentUser = Users.findOne({ userId: Auth.userID }, { fields: { presenter: 1 } });
2017-09-21 05:05:17 +08:00
return currentUser ? currentUser.presenter : false;
};
const filterAnnotationList = () => {
const multiUserPenOnly = getFromUserSettings('bbb_multi_user_pen_only', WHITEBOARD_TOOLBAR.multiUserPenOnly);
const amIPresenter = isPresenter();
let filteredAnnotationList = WHITEBOARD_TOOLBAR.tools;
if (!amIPresenter && multiUserPenOnly) {
filteredAnnotationList = [{
icon: 'pen_tool',
value: 'pencil',
}];
}
const presenterTools = getFromUserSettings('bbb_presenter_tools', WHITEBOARD_TOOLBAR.presenterTools);
if (amIPresenter && Array.isArray(presenterTools)) {
filteredAnnotationList = WHITEBOARD_TOOLBAR.tools.filter(el =>
presenterTools.includes(el.value));
}
const multiUserTools = getFromUserSettings('bbb_multi_user_tools', WHITEBOARD_TOOLBAR.multiUserTools);
if (!amIPresenter && !multiUserPenOnly && Array.isArray(multiUserTools)) {
filteredAnnotationList = WHITEBOARD_TOOLBAR.tools.filter(el =>
multiUserTools.includes(el.value));
}
return filteredAnnotationList;
};
2017-04-20 02:27:00 +08:00
export default {
2017-09-22 08:18:15 +08:00
undoAnnotation,
clearWhiteboard,
changeWhiteboardMode,
getCurrentPalmRejectionMode,
setInitialPalmRejectionMode,
setPalmRejectionMode,
2017-09-22 08:18:15 +08:00
setInitialWhiteboardToolbarValues,
getCurrentDrawSettings,
setFontSize,
setTool,
setThickness,
setColor,
setTextShapeObject,
getTextShapeActiveId,
isPresenter,
filterAnnotationList,
2017-04-20 02:27:00 +08:00
};