Skip to content
Snippets Groups Projects
Commit b4f9d88f authored by Oswaldo Acauan's avatar Oswaldo Acauan
Browse files

Refactor API Cursor's

parent e6445760
No related branches found
No related tags found
No related merge requests found
Showing
with 123 additions and 51 deletions
import Cursor from '/imports/api/cursor';
import Logger from '/imports/startup/server/logger';
export default function clearCursor(meetingId) {
if (meetingId) {
return Cursor.remove({ meetingId }, Logger.info(`Cleared Cursor (${meetingId})`));
} else {
return Cursor.remove({}, Logger.info('Cleared Cursor (all)'));
}
};
[Trash Info]
Path=imports/api/cursor/server/modifiers/clearCursors.js
DeletionDate=2016-11-18T09:49:05
[Trash Info]
Path=imports/api/cursor/server/modifiers/eventHandlers.js
DeletionDate=2016-11-18T09:49:29
[Trash Info]
Path=imports/api/cursor/server/publications.js
DeletionDate=2016-11-18T09:46:05
import RedisPubSub from '/imports/startup/server/redis';
import handleCursorUpdate from './handlers/cursorUpdate';
RedisPubSub.on('presentation_cursor_updated_message', handleCursorUpdate);
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;
check(meetingId, String);
check(x, Number);
check(y, Number);
return updateCursor(meetingId, x, y);
};
import './eventHandlers';
import './methods';
import './publishers';
import { Meteor } from 'meteor/meteor';
Meteor.methods({
});
import Cursor from '/imports/api/cursor';
import Logger from '/imports/startup/server/logger';
export default function clearCursor(meetingId) {
if (meetingId) {
return Cursor.remove({ meetingId }, Logger.info(`Cleared Cursor (${meetingId})`));
} else {
return Cursor.remove({}, Logger.info('Cleared Cursor (all)'));
}
};
import Cursor from '/imports/api/cursor';
import { logger } from '/imports/startup/server/logger';
// called on server start and meeting end
export function clearCursorCollection() {
const meetingId = arguments[0];
if (meetingId != null) {
return Cursor.remove({
meetingId: meetingId,
}, () => logger.info(`cleared Cursor Collection (meetingId: ${meetingId})!`));
} else {
return Cursor.remove({}, () => logger.info('cleared Cursor Collection (all meetings)!'));
}
};
import Cursor from '/imports/api/cursor';
import { logger } from '/imports/startup/server/logger';
import updateCursor from './updateCursor';
export function initializeCursor(meetingId) {
return Cursor.upsert({
meetingId: meetingId,
}, {
meetingId: meetingId,
x: 0,
y: 0,
}, (err, numChanged) => {
if (err) {
return logger.error(`err upserting cursor for ${meetingId}`);
}
export default function initializeCursor(meetingId) {
check(meetingId, String);
});
return updateCursor(meetingId, 0, 0);
};
import Logger from '/imports/startup/server/logger';
import Cursor from '/imports/api/cursor';
export default function updateCursor(meetingId, x = 0, y = 0) {
check(meetingId, String);
check(x, Number);
check(y, Number);
const selector = {
meetingId,
};
const modifier = {
$set: {
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.info(`Updated cursor meeting=${meetingId}`);
}
};
return Cursor.upsert(selector, modifier, cb);
};
import Cursor from '/imports/api/cursor';
import { logger } from '/imports/startup/server/logger';
export function updateCursorLocation(meetingId, cursorObject) {
return Cursor.upsert({
meetingId: meetingId,
}, {
$set: {
meetingId: meetingId,
x: cursorObject.x,
y: cursorObject.y,
},
}, (err, numChanged) => {
if (err != null) {
return logger.error(`_unsucc update of cursor for ${meetingId} err=${JSON.stringify(err)}`);
}
});
};
import Cursor from '/imports/api/cursor';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
Meteor.publish('cursor', (credentials) => {
// TODO: Some publishers have ACL and others dont
// if (!isAllowedTo('@@@', credentials)) {
// this.error(new Meteor.Error(402, "The user was not authorized to subscribe for 'cursor'"));
// }
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
Logger.info(`Publishing Cursor for ${meetingId} ${requesterUserId} ${requesterToken}`);
return Cursor.find({ meetingId });
});
import { check } from 'meteor/check';
import Meetings from '/imports/api/meetings';
import Logger from '/imports/startup/server/logger';
import { initializeCursor } from '/imports/api/cursor/server/modifiers/initializeCursor';
import initializeCursor from '/imports/api/cursor/server/modifiers/initializeCursor';
export default function addMeeting(meeting) {
const APP_CONFIG = Meteor.settings.public.app;
......
......@@ -7,7 +7,7 @@ import clearChats from '/imports/api/chat/server/modifiers/clearChats';
import { clearShapesCollection } from '/imports/api/shapes/server/modifiers/clearShapesCollection';
import clearSlides from '/imports/api/slides/server/modifiers/clearSlides';
import clearPolls from '/imports/api/polls/server/modifiers/clearPolls';
import { clearCursorCollection } from '/imports/api/cursor/server/modifiers/clearCursorCollection';
import clearCursor from '/imports/api/cursor/server/modifiers/clearCursor';
import { clearCaptionsCollection }
from '/imports/api/captions/server/modifiers/clearCaptionsCollection';
import clearPresentations from '/imports/api/presentations/server/modifiers/clearPresentations';
......@@ -16,7 +16,7 @@ export default function clearMeetings() {
return Meetings.remove({}, (err) => {
clearCaptionsCollection();
clearChats();
clearCursorCollection();
clearCursor();
clearPresentations();
clearPolls();
clearShapesCollection();
......
......@@ -7,7 +7,7 @@ import clearChats from '/imports/api/chat/server/modifiers/clearChats';
import { clearShapesCollection } from '/imports/api/shapes/server/modifiers/clearShapesCollection';
import clearSlides from '/imports/api/slides/server/modifiers/clearSlides';
import clearPolls from '/imports/api/polls/server/modifiers/clearPolls';
import { clearCursorCollection } from '/imports/api/cursor/server/modifiers/clearCursorCollection';
import clearCursor from '/imports/api/cursor/server/modifiers/clearCursor';
import { clearCaptionsCollection }
from '/imports/api/captions/server/modifiers/clearCaptionsCollection';
import clearPresentations from '/imports/api/presentations/server/modifiers/clearPresentations';
......
......@@ -3,7 +3,7 @@ import Logger from '/imports/startup/server/logger';
export default function clearSlides(meetingId) {
if (meetingId) {
return Slides.remove({ meetingId: meetingId }, Logger.info(`Cleared Slides (${meetingId})`));
return Slides.remove({ meetingId }, Logger.info(`Cleared Slides (${meetingId})`));
} else {
return Slides.remove({}, Logger.info('Cleared Slides (all)'));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment