bigbluebutton-Github/bigbluebutton-html5/imports/api/annotations/server/handlers/whiteboardSend.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-19 01:35:28 +08:00
import { check } from 'meteor/check';
2019-10-23 09:26:25 +08:00
import AnnotationsStreamer from '/imports/api/annotations/server/streamer';
import addAnnotation from '../modifiers/addAnnotation';
2020-12-10 23:07:06 +08:00
import Metrics from '/imports/startup/server/metrics';
2016-11-19 01:35:28 +08:00
2020-12-11 01:07:46 +08:00
const { queueMetrics } = Meteor.settings.private.redis.metrics;
2018-05-30 22:19:19 +08:00
const ANNOTATION_PROCCESS_INTERVAL = 60;
let annotationsQueue = {};
let annotationsRecieverIsRunning = false;
const proccess = () => {
if (!Object.keys(annotationsQueue).length) {
annotationsRecieverIsRunning = false;
return;
}
annotationsRecieverIsRunning = true;
2019-10-23 09:26:25 +08:00
Object.keys(annotationsQueue).forEach((meetingId) => {
AnnotationsStreamer(meetingId).emit('added', { meetingId, annotations: annotationsQueue[meetingId] });
2020-12-16 03:20:32 +08:00
if (queueMetrics) {
Metrics.setAnnotationQueueLength(meetingId, 0);
}
});
annotationsQueue = {};
2018-05-30 22:19:19 +08:00
Meteor.setTimeout(proccess, ANNOTATION_PROCCESS_INTERVAL);
};
export default function handleWhiteboardSend({ header, body }, meetingId) {
const userId = header.userId;
const annotation = body.annotation;
2016-11-19 01:35:28 +08:00
check(userId, String);
check(annotation, Object);
2016-11-19 01:35:28 +08:00
const whiteboardId = annotation.wbId;
2016-11-19 01:35:28 +08:00
check(whiteboardId, String);
2020-12-11 01:07:46 +08:00
if (!annotationsQueue.hasOwnProperty(meetingId)) {
annotationsQueue[meetingId] = [];
}
annotationsQueue[meetingId].push({ meetingId, whiteboardId, userId, annotation });
2020-12-11 01:07:46 +08:00
if (queueMetrics) {
Metrics.setAnnotationQueueLength(meetingId, annotationsQueue[meetingId].length);
}
if (!annotationsRecieverIsRunning) proccess();
return addAnnotation(meetingId, whiteboardId, userId, annotation);
2017-06-03 03:25:02 +08:00
}