ec07b4434d
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
48 lines
1.1 KiB
JavaScript
Executable File
48 lines
1.1 KiB
JavaScript
Executable File
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);
|
|
|
|
function updateCursor(meetingId, userId, x = -1, y = -1) {
|
|
const selector = {
|
|
meetingId,
|
|
userId,
|
|
};
|
|
|
|
const modifier = {
|
|
$set: {
|
|
userId,
|
|
meetingId,
|
|
x,
|
|
y,
|
|
},
|
|
};
|
|
|
|
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 });
|
|
|
|
export function publishCursorUpdate(x, y) {
|
|
throttledEmit('publish', {
|
|
credentials: Auth.credentials,
|
|
payload: {
|
|
xPercent: x,
|
|
yPercent: y,
|
|
},
|
|
});
|
|
|
|
return updateCursor(Auth.meetingID, Auth.userID, x, y);
|
|
}
|
|
|
|
export default Cursor;
|