2020-02-07 04:47:28 +08:00
|
|
|
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';
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2022-05-04 20:40:56 +08:00
|
|
|
export default function sendAnnotationHelper(annotations, meetingId, requesterUserId) {
|
2020-02-07 04:47:28 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2022-05-04 20:40:56 +08:00
|
|
|
const EVENT_NAME = 'SendWhiteboardAnnotationsPubMsg';
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2021-05-04 22:38:56 +08:00
|
|
|
try {
|
2022-05-04 20:40:56 +08:00
|
|
|
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]) => {
|
2022-05-04 20:40:56 +08:00
|
|
|
const whiteboardId = whiteboardAnnotations[0].wbId;
|
|
|
|
check(whiteboardId, String);
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2022-05-04 20:40:56 +08:00
|
|
|
const payload = {
|
|
|
|
whiteboardId,
|
|
|
|
annotations: whiteboardAnnotations,
|
2022-09-28 20:03:59 +08:00
|
|
|
html5InstanceId: parseInt(process.env.INSTANCE_ID, 10) || 1,
|
2022-05-04 20:40:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
});
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2021-05-04 22:38:56 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method sendAnnotationHelper ${err.stack}`);
|
|
|
|
}
|
2020-02-07 04:47:28 +08:00
|
|
|
}
|