Merge remote-tracking branch 'upstream/master' into refactor-api-shapes

* upstream/master:
  Remove wrong commited files
  Refactor API Cursor's
This commit is contained in:
Oswaldo Acauan 2016-11-18 17:35:53 +00:00
commit b0e784ec60
15 changed files with 104 additions and 79 deletions

View File

@ -0,0 +1,4 @@
import RedisPubSub from '/imports/startup/server/redis';
import handleCursorUpdate from './handlers/cursorUpdate';
RedisPubSub.on('presentation_cursor_updated_message', handleCursorUpdate);

View File

@ -0,0 +1,15 @@
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);
};

View File

@ -0,0 +1,3 @@
import './eventHandlers';
import './methods';
import './publishers';

View File

@ -0,0 +1,4 @@
import { Meteor } from 'meteor/meteor';
Meteor.methods({
});

View File

@ -0,0 +1,10 @@
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})`));
}
return Cursor.remove({}, Logger.info('Cleared Cursor (all)'));
};

View File

@ -1,14 +0,0 @@
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)!'));
}
};

View File

@ -1,14 +0,0 @@
import { updateCursorLocation } from './updateCursorLocation';
import { eventEmitter } from '/imports/startup/server';
eventEmitter.on('presentation_cursor_updated_message', function (arg) {
const meetingId = arg.payload.meeting_id;
const cursor = {
x: arg.payload.x_percent,
y: arg.payload.y_percent,
};
// update the location of the cursor on the whiteboard
updateCursorLocation(meetingId, cursor);
return arg.callback();
});

View File

@ -1,17 +1,8 @@
import Cursor from '/imports/api/cursor'; import Cursor from '/imports/api/cursor';
import { logger } from '/imports/startup/server/logger'; import updateCursor from './updateCursor';
export function initializeCursor(meetingId) { export default function initializeCursor(meetingId) {
return Cursor.upsert({ check(meetingId, String);
meetingId: meetingId,
}, {
meetingId: meetingId,
x: 0,
y: 0,
}, (err, numChanged) => {
if (err) {
return logger.error(`err upserting cursor for ${meetingId}`);
}
}); return updateCursor(meetingId, 0, 0);
}; };

View File

@ -0,0 +1,37 @@
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);
};

View File

@ -1,19 +0,0 @@
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)}`);
}
});
};

View File

@ -1,10 +0,0 @@
import Cursor from '/imports/api/cursor';
import { logger } from '/imports/startup/server/logger';
Meteor.publish('cursor', function (credentials) {
const { meetingId } = credentials;
logger.info(`publishing cursor for ${meetingId}`);
return Cursor.find({
meetingId: meetingId,
});
});

View File

@ -0,0 +1,22 @@
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 });
});

View File

@ -1,7 +1,7 @@
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import Meetings from '/imports/api/meetings'; import Meetings from '/imports/api/meetings';
import Logger from '/imports/startup/server/logger'; 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) { export default function addMeeting(meeting) {
const APP_CONFIG = Meteor.settings.public.app; const APP_CONFIG = Meteor.settings.public.app;

View File

@ -3,8 +3,8 @@ import Logger from '/imports/startup/server/logger';
export default function clearSlides(meetingId) { export default function clearSlides(meetingId) {
if (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)'));
} }
return Slides.remove({}, Logger.info('Cleared Slides (all)'));
}; };

View File

@ -1,11 +1,7 @@
import '/imports/startup/server'; import '/imports/startup/server';
import '/imports/api/chat/server'; import '/imports/api/chat/server';
import '/imports/api/cursor/server/publications'; import '/imports/api/cursor/server';
import '/imports/api/cursor/server/modifiers/clearCursorCollection';
import '/imports/api/cursor/server/modifiers/initializeCursor';
import '/imports/api/cursor/server/modifiers/updateCursorLocation';
import '/imports/api/cursor/server/modifiers/eventHandlers';
import '/imports/api/deskshare/server/publications'; import '/imports/api/deskshare/server/publications';
import '/imports/api/deskshare/server/modifiers/clearDeskshareCollection'; import '/imports/api/deskshare/server/modifiers/clearDeskshareCollection';