2016-11-19 01:35:28 +08:00
|
|
|
import { check } from 'meteor/check';
|
2018-05-12 00:01:24 +08:00
|
|
|
import { AnnotationsStreamer } from '/imports/api/annotations';
|
2017-10-12 08:52:57 +08:00
|
|
|
import addAnnotation from '../modifiers/addAnnotation';
|
2016-11-19 01:35:28 +08:00
|
|
|
|
2018-05-30 22:19:19 +08:00
|
|
|
const ANNOTATION_PROCCESS_INTERVAL = 60;
|
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
let annotationsQueue = {};
|
|
|
|
let annotationsRecieverIsRunning = false;
|
|
|
|
|
|
|
|
const proccess = () => {
|
|
|
|
if (!Object.keys(annotationsQueue).length) {
|
|
|
|
annotationsRecieverIsRunning = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
annotationsRecieverIsRunning = true;
|
|
|
|
Object.keys(annotationsQueue).forEach(meetingId => {
|
|
|
|
AnnotationsStreamer.emit('added', { meetingId, annotations: annotationsQueue[meetingId] });
|
|
|
|
});
|
|
|
|
annotationsQueue = {};
|
|
|
|
|
2018-05-30 22:19:19 +08:00
|
|
|
Meteor.setTimeout(proccess, ANNOTATION_PROCCESS_INTERVAL);
|
2018-05-12 00:01:24 +08:00
|
|
|
};
|
|
|
|
|
2017-10-12 08:52:57 +08:00
|
|
|
export default function handleWhiteboardSend({ header, body }, meetingId) {
|
|
|
|
const userId = header.userId;
|
|
|
|
const annotation = body.annotation;
|
2016-11-19 01:35:28 +08:00
|
|
|
|
2017-10-12 08:52:57 +08:00
|
|
|
check(userId, String);
|
|
|
|
check(annotation, Object);
|
2016-11-19 01:35:28 +08:00
|
|
|
|
2017-10-12 08:52:57 +08:00
|
|
|
const whiteboardId = annotation.wbId;
|
2016-11-19 01:35:28 +08:00
|
|
|
check(whiteboardId, String);
|
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
if(!annotationsQueue.hasOwnProperty(meetingId)) {
|
|
|
|
annotationsQueue[meetingId] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
annotationsQueue[meetingId].push({ meetingId, whiteboardId, userId, annotation });
|
|
|
|
if (!annotationsRecieverIsRunning) proccess();
|
|
|
|
|
2017-10-12 08:52:57 +08:00
|
|
|
return addAnnotation(meetingId, whiteboardId, userId, annotation);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|