bigbluebutton-Github/bigbluebutton-html5/imports/api/annotations/index.js
Oswaldo Acauan ec07b4434d Change cursor and annotation to user streams and add optimistic updates
WIP | Use streams to cursor and optimistic updates

WIP | Use streamss to whiteboard and optimistic updates

WIP | Remove fake delay

Add two way batching (server/client client/server)

Fix null userId exception and remove logs

wip

Add two way batching (server/client client/server) for cursor

Remove message frequency from draw-listeners component since we handle on message publication

Handle clear and undo messages
2018-05-28 14:46:14 -03:00

56 lines
1.6 KiB
JavaScript
Executable File

import { Meteor } from 'meteor/meteor';
import Users from '/imports/api/users';
const Annotations = new Mongo.Collection('annotations');
const Streamer = new Meteor.Streamer('annotations', { retransmit: false, });
if (Meteor.isServer) {
// types of queries for the annotations:
// 1. meetingId, whiteboardId
// 2. meetingId, whiteboardId, userId
// 3. meetingId, id, userId
// 4. meetingId, whiteboardId, id
// These 2 indexes seem to cover all of the cases
// Either mongo uses a whole or a part of the compound index
// Or it uses 'id' and then matches other fields
Annotations._ensureIndex({ id: 1 });
Annotations._ensureIndex({ meetingId: 1, whiteboardId: 1, userId: 1 });
import sendAnnotation from './server/methods/sendAnnotation';
Streamer.on('publish', ({ credentials, payload }) => {
payload.forEach(annotation => sendAnnotation(credentials, annotation));
});
Streamer.allowRead(function(eventName, ...args) {
return true;
});
Streamer.allowEmit(function(eventName, { meetingId }) {
return this.userId && this.userId.includes(meetingId);
});
Streamer.allowWrite(function(eventName, { credentials }) {
if (!this.userId || !credentials) return false;
const { meetingId, requesterUserId: userId, requesterToken: authToken } = credentials;
const user = Users.findOne({
meetingId,
userId,
authToken,
connectionId: this.connection.id,
validated: true,
connectionStatus: 'online',
});
if (!user) return false;
return true;
});
}
export default Annotations;
export const AnnotationsStreamer = Streamer;