bigbluebutton-Github/bigbluebutton-html5/imports/api/annotations/server/methods/sendAnnotationHelper.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

import RedisPubSub from '/imports/startup/server/redis';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
2021-05-04 22:38:56 +08:00
import Logger from '/imports/startup/server/logger';
export default function sendAnnotationHelper(annotations, meetingId, requesterUserId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'SendWhiteboardAnnotationsPubMsg';
2021-05-04 22:38:56 +08:00
try {
check(annotations, Array);
// TODO see if really necessary, don't know if it's possible
// to have annotations from different pages
// group annotations by same whiteboardId
2023-02-18 01:39:52 +08:00
const groupedAnnotations = annotations.reduce((r, v, i, a, k = v.wbId) => ((r[k] || (r[k] = [])).push(v), r), {}) //groupBy wbId
Object.entries(groupedAnnotations).forEach(([_, whiteboardAnnotations]) => {
const whiteboardId = whiteboardAnnotations[0].wbId;
check(whiteboardId, String);
const payload = {
whiteboardId,
annotations: whiteboardAnnotations,
html5InstanceId: parseInt(process.env.INSTANCE_ID, 10) || 1,
};
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
});
2021-05-04 22:38:56 +08:00
} catch (err) {
Logger.error(`Exception while invoking method sendAnnotationHelper ${err.stack}`);
}
}