2019-11-14 00:53:45 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2019-10-25 04:48:03 +08:00
|
|
|
import publishCursorUpdate from './methods/publishCursorUpdate';
|
|
|
|
|
2019-12-05 02:22:31 +08:00
|
|
|
const { streamerLog } = Meteor.settings.private.serverLog;
|
|
|
|
|
2019-10-25 04:48:03 +08:00
|
|
|
export function removeCursorStreamer(meetingId) {
|
2019-11-14 00:53:45 +08:00
|
|
|
Logger.info(`Removing Cursor streamer object for meeting ${meetingId}`);
|
2019-10-25 04:48:03 +08:00
|
|
|
delete Meteor.StreamerCentral.instances[`cursor-${meetingId}`];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addCursorStreamer(meetingId) {
|
|
|
|
const streamer = new Meteor.Streamer(`cursor-${meetingId}`, { retransmit: false });
|
2019-12-05 02:22:31 +08:00
|
|
|
if (streamerLog) {
|
2020-11-24 03:35:59 +08:00
|
|
|
Logger.debug('Cursor streamer created', { meetingId });
|
2019-12-05 02:22:31 +08:00
|
|
|
}
|
2019-12-04 23:42:41 +08:00
|
|
|
|
2019-10-25 04:48:03 +08:00
|
|
|
streamer.allowRead(function allowRead() {
|
2019-12-05 02:22:31 +08:00
|
|
|
if (streamerLog) {
|
2020-11-24 03:35:59 +08:00
|
|
|
Logger.debug('Cursor streamer called allowRead', { userId: this.userId, meetingId });
|
2019-12-05 02:22:31 +08:00
|
|
|
}
|
2019-10-25 04:48:03 +08:00
|
|
|
return this.userId && this.userId.includes(meetingId);
|
|
|
|
});
|
|
|
|
|
|
|
|
streamer.allowWrite(function allowWrite() {
|
|
|
|
return this.userId && this.userId.includes(meetingId);
|
|
|
|
});
|
|
|
|
|
|
|
|
streamer.on('publish', (message) => {
|
2020-02-07 04:47:28 +08:00
|
|
|
publishCursorUpdate(meetingId, message.userId, message.payload);
|
2019-10-25 04:48:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function get(meetingId) {
|
|
|
|
return Meteor.StreamerCentral.instances[`cursor-${meetingId}`];
|
|
|
|
}
|