bigbluebutton-Github/bigbluebutton-html5/imports/api/group-chat-msg/server/handlers/groupChatMsgBroadcast.js

26 lines
709 B
JavaScript
Raw Normal View History

import { check } from 'meteor/check';
import throttle from 'lodash.throttle';
import addGroupChatMsg from '../modifiers/addGroupChatMsg';
import addBulkGroupChatMsgs from '../modifiers/addBulkGroupChatMsgs';
const { bufferChatInsertsMs } = Meteor.settings.public.chat;
const msgBuffer = [];
const bulkFn = throttle(addBulkGroupChatMsgs, bufferChatInsertsMs);
export default function handleGroupChatMsgBroadcast({ body }, meetingId) {
const { chatId, msg } = body;
check(meetingId, String);
check(chatId, String);
check(msg, Object);
if (bufferChatInsertsMs) {
msgBuffer.push({ meetingId, chatId, msg });
bulkFn(msgBuffer);
} else {
addGroupChatMsg(meetingId, chatId, msg);
}
}