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

115 lines
3.5 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/api/users';
import Auth from '/imports/ui/services/auth';
import WhiteboardMultiUser from '/imports/api/whiteboard-multi-user/';
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 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);
2017-09-22 08:18:15 +08:00
};
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 : '';
};
2018-04-10 07:18:49 +08:00
const getMultiUserStatus = (whiteboardId) => {
const data = WhiteboardMultiUser.findOne({ meetingId: Auth.meetingID, whiteboardId });
2017-09-21 05:05:17 +08:00
return data ? data.multiUser : false;
};
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);
let filteredAnnotationList = WHITEBOARD_TOOLBAR.tools;
if (!isPresenter() && multiUserPenOnly) {
filteredAnnotationList = [{
icon: 'pen_tool',
value: 'pencil',
}];
}
const presenterTools = getFromUserSettings('bbb_presenter_tools', WHITEBOARD_TOOLBAR.presenterTools);
if (isPresenter() && Array.isArray(presenterTools)) {
filteredAnnotationList = WHITEBOARD_TOOLBAR.tools.filter(el =>
presenterTools.includes(el.value));
}
const multiUserTools = getFromUserSettings('bbb_multi_user_tools', WHITEBOARD_TOOLBAR.multiUserTools);
if (!isPresenter() && !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,
setInitialWhiteboardToolbarValues,
getCurrentDrawSettings,
setFontSize,
setTool,
setThickness,
setColor,
setTextShapeObject,
getTextShapeActiveId,
getMultiUserStatus,
isPresenter,
filterAnnotationList,
2017-04-20 02:27:00 +08:00
};