Merged 2.0 and 1.1 cursor apis
This commit is contained in:
parent
47d9b53cc2
commit
3f8e24c12e
@ -1 +1,13 @@
|
||||
export default new Mongo.Collection('cursor');
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
const Cursor = new Mongo.Collection('cursor2x');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// types of queries for the cursor:
|
||||
// 1. meetingId (clear)
|
||||
// 2. meetingId, userId
|
||||
|
||||
Cursor._ensureIndex({ meetingId: 1, userId: 1 });
|
||||
}
|
||||
|
||||
export default Cursor;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import RedisPubSub from '/imports/startup/server/redis2x';
|
||||
import handleCursorUpdate from './handlers/cursorUpdate';
|
||||
|
||||
RedisPubSub.on('presentation_cursor_updated_message', handleCursorUpdate);
|
||||
RedisPubSub.on('SendCursorPositionEvtMsg', handleCursorUpdate);
|
||||
|
@ -1,15 +1,14 @@
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { check } from 'meteor/check';
|
||||
import updateCursor from '../modifiers/updateCursor';
|
||||
|
||||
export default function handleCursorUpdate({ payload }) {
|
||||
const meetingId = payload.meeting_id;
|
||||
const x = payload.x_percent;
|
||||
const y = payload.y_percent;
|
||||
export default function handleCursorUpdate({ header, body }, meetingId) {
|
||||
const userId = header.userId;
|
||||
const x = body.xPercent;
|
||||
const y = body.yPercent;
|
||||
|
||||
check(meetingId, String);
|
||||
check(userId, String);
|
||||
check(x, Number);
|
||||
check(y, Number);
|
||||
|
||||
return updateCursor(meetingId, x, y);
|
||||
return updateCursor(meetingId, userId, x, y);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import publishCursorUpdate from './methods/publishCursorUpdate';
|
||||
|
||||
Meteor.methods({
|
||||
publishCursorUpdate,
|
||||
});
|
||||
|
@ -1,43 +1,31 @@
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import { getMultiUserStatus } from '/imports/api/common/server/helpers';
|
||||
import RedisPubSub from '/imports/startup/server/redis2x';
|
||||
import Acl from '/imports/startup/acl';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
// import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
||||
import Presentations from '/imports/api/1.1/presentations';
|
||||
|
||||
export default function publishCursorUpdate(credentials, coordinates) {
|
||||
|
||||
export default function publishCursorUpdate(credentials, payload) {
|
||||
const REDIS_CONFIG = Meteor.settings.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.presentation;
|
||||
const EVENT_NAME = 'send_cursor_update';
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'SendCursorPositionPubMsg';
|
||||
|
||||
const { meetingId, requesterUserId, requesterToken } = credentials;
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(requesterToken, String);
|
||||
check(coordinates, {
|
||||
check(payload, {
|
||||
xPercent: Number,
|
||||
yPercent: Number,
|
||||
});
|
||||
|
||||
// if (!isAllowedTo('moveCursor', credentials)) {
|
||||
// throw new Meteor.Error('not-allowed', `You are not allowed to move the Cursor`);
|
||||
// }
|
||||
|
||||
const Presentation = Presentations.findOne({
|
||||
meetingId,
|
||||
'presentation.current': true,
|
||||
});
|
||||
|
||||
if (!Presentation) {
|
||||
const allowed = Acl.can('methods.moveCursor', credentials) || getMultiUserStatus(meetingId);
|
||||
if (!allowed) {
|
||||
throw new Meteor.Error(
|
||||
'presentation-not-found', 'You need a presentation to be able to move the cursor');
|
||||
'not-allowed', `User ${requesterUserId} is not allowed to move the cursor`,
|
||||
);
|
||||
}
|
||||
|
||||
const payload = {
|
||||
x_percent: coordinates.xPercent,
|
||||
meeting_id: meetingId,
|
||||
y_percent: coordinates.yPercent,
|
||||
};
|
||||
|
||||
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
|
||||
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Cursor from '/imports/api/1.1/cursor';
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function clearCursor(meetingId) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Cursor from '/imports/api/1.1/cursor';
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import updateCursor from './updateCursor';
|
||||
|
||||
export default function initializeCursor(meetingId) {
|
||||
check(meetingId, String);
|
||||
|
||||
return updateCursor(meetingId, 0, 0);
|
||||
return updateCursor(meetingId, -1, -1);
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import Cursor from '/imports/api/1.1/cursor';
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export default function updateCursor(meetingId, x = 0, y = 0) {
|
||||
export default function updateCursor(meetingId, userId, x = -1, y = -1) {
|
||||
check(meetingId, String);
|
||||
check(userId, String);
|
||||
check(x, Number);
|
||||
check(y, Number);
|
||||
|
||||
const selector = {
|
||||
meetingId,
|
||||
userId,
|
||||
};
|
||||
|
||||
const modifier = {
|
||||
$set: {
|
||||
userId,
|
||||
meetingId,
|
||||
x,
|
||||
y,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Cursor from '/imports/api/1.1/cursor';
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
@ -12,7 +12,7 @@ function cursor(credentials) {
|
||||
check(requesterUserId, String);
|
||||
check(requesterToken, String);
|
||||
|
||||
Logger.debug(`Publishing Cursor for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
||||
Logger.debug(`Publishing Cursor2x for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
||||
|
||||
return Cursor.find({ meetingId });
|
||||
}
|
||||
@ -22,5 +22,5 @@ function publish(...args) {
|
||||
return mapToAcl('subscriptions.cursor', boundCursor)(args);
|
||||
}
|
||||
|
||||
Meteor.publish('cursor', publish);
|
||||
Meteor.publish('cursor2x', publish);
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
const Cursor = new Mongo.Collection('cursor2x');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// types of queries for the cursor:
|
||||
// 1. meetingId (clear)
|
||||
// 2. meetingId, userId
|
||||
|
||||
Cursor._ensureIndex({ meetingId: 1, userId: 1 });
|
||||
}
|
||||
|
||||
export default Cursor;
|
@ -1,4 +0,0 @@
|
||||
import RedisPubSub from '/imports/startup/server/redis2x';
|
||||
import handleCursorUpdate from './handlers/cursorUpdate';
|
||||
|
||||
RedisPubSub.on('SendCursorPositionEvtMsg', handleCursorUpdate);
|
@ -1,14 +0,0 @@
|
||||
import { check } from 'meteor/check';
|
||||
import updateCursor from '../modifiers/updateCursor';
|
||||
|
||||
export default function handleCursorUpdate({ header, body }, meetingId) {
|
||||
const userId = header.userId;
|
||||
const x = body.xPercent;
|
||||
const y = body.yPercent;
|
||||
|
||||
check(userId, String);
|
||||
check(x, Number);
|
||||
check(y, Number);
|
||||
|
||||
return updateCursor(meetingId, userId, x, y);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
import './eventHandlers';
|
||||
import './methods';
|
||||
import './publishers';
|
@ -1,6 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import publishCursorUpdate from './methods/publishCursorUpdate';
|
||||
|
||||
Meteor.methods({
|
||||
publishCursorUpdate,
|
||||
});
|
@ -1,31 +0,0 @@
|
||||
import { getMultiUserStatus } from '/imports/api/common/server/helpers';
|
||||
import RedisPubSub from '/imports/startup/server/redis2x';
|
||||
import Acl from '/imports/startup/acl';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
|
||||
export default function publishCursorUpdate(credentials, payload) {
|
||||
const REDIS_CONFIG = Meteor.settings.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const EVENT_NAME = 'SendCursorPositionPubMsg';
|
||||
|
||||
const { meetingId, requesterUserId, requesterToken } = credentials;
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(requesterToken, String);
|
||||
check(payload, {
|
||||
xPercent: Number,
|
||||
yPercent: Number,
|
||||
});
|
||||
|
||||
const allowed = Acl.can('methods.moveCursor', credentials) || getMultiUserStatus(meetingId);
|
||||
if (!allowed) {
|
||||
throw new Meteor.Error(
|
||||
'not-allowed', `User ${requesterUserId} is not allowed to move the cursor`,
|
||||
);
|
||||
}
|
||||
|
||||
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function clearCursor(meetingId) {
|
||||
if (meetingId) {
|
||||
return Cursor.remove({ meetingId }, Logger.info(`Cleared Cursor (${meetingId})`));
|
||||
}
|
||||
|
||||
return Cursor.remove({}, Logger.info('Cleared Cursor (all)'));
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import updateCursor from './updateCursor';
|
||||
|
||||
export default function initializeCursor(meetingId) {
|
||||
check(meetingId, String);
|
||||
|
||||
return updateCursor(meetingId, -1, -1);
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export default function updateCursor(meetingId, userId, x = -1, y = -1) {
|
||||
check(meetingId, String);
|
||||
check(userId, String);
|
||||
check(x, Number);
|
||||
check(y, Number);
|
||||
|
||||
const selector = {
|
||||
meetingId,
|
||||
userId,
|
||||
};
|
||||
|
||||
const modifier = {
|
||||
$set: {
|
||||
userId,
|
||||
meetingId,
|
||||
x,
|
||||
y,
|
||||
},
|
||||
};
|
||||
|
||||
const cb = (err, numChanged) => {
|
||||
if (err) {
|
||||
return Logger.error(`Upserting cursor to collection: ${err}`);
|
||||
}
|
||||
|
||||
const { insertedId } = numChanged;
|
||||
if (insertedId) {
|
||||
return Logger.info(`Initialized cursor meeting=${meetingId}`);
|
||||
}
|
||||
|
||||
if (numChanged) {
|
||||
return Logger.debug(`Updated cursor meeting=${meetingId}`);
|
||||
}
|
||||
};
|
||||
|
||||
return Cursor.upsert(selector, modifier, cb);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
import Cursor from '/imports/api/2.0/cursor';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
import mapToAcl from '/imports/startup/mapToAcl';
|
||||
|
||||
function cursor(credentials) {
|
||||
const { meetingId, requesterUserId, requesterToken } = credentials;
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(requesterToken, String);
|
||||
|
||||
Logger.debug(`Publishing Cursor2x for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
||||
|
||||
return Cursor.find({ meetingId });
|
||||
}
|
||||
|
||||
function publish(...args) {
|
||||
const boundCursor = cursor.bind(this);
|
||||
return mapToAcl('subscriptions.cursor', boundCursor)(args);
|
||||
}
|
||||
|
||||
Meteor.publish('cursor2x', publish);
|
||||
|
Loading…
Reference in New Issue
Block a user