bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/cursor/service.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import { CursorStreamer } from '/imports/api/cursor';
import { throttle } from 'lodash';
const Cursor = new Mongo.Collection(null);
2018-07-27 03:05:55 +08:00
function updateCursor(meetingId, userId, payload) {
const selector = {
meetingId,
userId,
2018-07-27 03:05:55 +08:00
whiteboardId: payload.whiteboardId,
};
const modifier = {
$set: {
userId,
meetingId,
2018-07-27 03:05:55 +08:00
...payload,
},
};
return Cursor.upsert(selector, modifier);
}
CursorStreamer.on('message', ({ meetingId, cursors }) => {
Object.keys(cursors).forEach(userId => {
if (Auth.meetingID === meetingId && Auth.userID === userId) return;
updateCursor(meetingId, userId, cursors[userId].x, cursors[userId].y);
});
});
const throttledEmit = throttle(CursorStreamer.emit.bind(CursorStreamer), 30, { 'trailing': false });
2018-07-27 03:05:55 +08:00
export function publishCursorUpdate(payload) {
throttledEmit('publish', {
credentials: Auth.credentials,
2018-07-27 03:05:55 +08:00
payload,
});
2018-07-27 03:05:55 +08:00
return updateCursor(Auth.meetingID, Auth.userID, payload);
}
export default Cursor;