diff --git a/bigbluebutton-html5/imports/api/cursor/server/eventHandlers.js b/bigbluebutton-html5/imports/api/cursor/server/eventHandlers.js new file mode 100644 index 0000000000..bc02337a12 --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/eventHandlers.js @@ -0,0 +1,4 @@ +import RedisPubSub from '/imports/startup/server/redis'; +import handleCursorUpdate from './handlers/cursorUpdate'; + +RedisPubSub.on('presentation_cursor_updated_message', handleCursorUpdate); diff --git a/bigbluebutton-html5/imports/api/cursor/server/handlers/cursorUpdate.js b/bigbluebutton-html5/imports/api/cursor/server/handlers/cursorUpdate.js new file mode 100644 index 0000000000..c14e2a7b9a --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/handlers/cursorUpdate.js @@ -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); +}; diff --git a/bigbluebutton-html5/imports/api/cursor/server/index.js b/bigbluebutton-html5/imports/api/cursor/server/index.js new file mode 100644 index 0000000000..92451ac76b --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/index.js @@ -0,0 +1,3 @@ +import './eventHandlers'; +import './methods'; +import './publishers'; diff --git a/bigbluebutton-html5/imports/api/cursor/server/methods.js b/bigbluebutton-html5/imports/api/cursor/server/methods.js new file mode 100644 index 0000000000..1ce65c3698 --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/methods.js @@ -0,0 +1,4 @@ +import { Meteor } from 'meteor/meteor'; + +Meteor.methods({ +}); diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursor.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursor.js new file mode 100755 index 0000000000..07fd887879 --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursor.js @@ -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)')); +}; diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursorCollection.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursorCollection.js deleted file mode 100755 index ff7fea4071..0000000000 --- a/bigbluebutton-html5/imports/api/cursor/server/modifiers/clearCursorCollection.js +++ /dev/null @@ -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)!')); - } -}; diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/eventHandlers.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/eventHandlers.js deleted file mode 100644 index 2e15d14446..0000000000 --- a/bigbluebutton-html5/imports/api/cursor/server/modifiers/eventHandlers.js +++ /dev/null @@ -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(); -}); diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/initializeCursor.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/initializeCursor.js index 172a98fe71..0b4c162e3c 100755 --- a/bigbluebutton-html5/imports/api/cursor/server/modifiers/initializeCursor.js +++ b/bigbluebutton-html5/imports/api/cursor/server/modifiers/initializeCursor.js @@ -1,17 +1,8 @@ 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); }; diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursor.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursor.js new file mode 100755 index 0000000000..2e6217849d --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursor.js @@ -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); +}; diff --git a/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursorLocation.js b/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursorLocation.js deleted file mode 100755 index f16c0a5f51..0000000000 --- a/bigbluebutton-html5/imports/api/cursor/server/modifiers/updateCursorLocation.js +++ /dev/null @@ -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)}`); - } - - }); -}; diff --git a/bigbluebutton-html5/imports/api/cursor/server/publications.js b/bigbluebutton-html5/imports/api/cursor/server/publications.js deleted file mode 100755 index 73c2a8c509..0000000000 --- a/bigbluebutton-html5/imports/api/cursor/server/publications.js +++ /dev/null @@ -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, - }); -}); diff --git a/bigbluebutton-html5/imports/api/cursor/server/publishers.js b/bigbluebutton-html5/imports/api/cursor/server/publishers.js new file mode 100644 index 0000000000..fd435ecbf7 --- /dev/null +++ b/bigbluebutton-html5/imports/api/cursor/server/publishers.js @@ -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 }); +}); diff --git a/bigbluebutton-html5/imports/api/meetings/server/modifiers/addMeeting.js b/bigbluebutton-html5/imports/api/meetings/server/modifiers/addMeeting.js index 7c9943b3b7..eb34b099f2 100755 --- a/bigbluebutton-html5/imports/api/meetings/server/modifiers/addMeeting.js +++ b/bigbluebutton-html5/imports/api/meetings/server/modifiers/addMeeting.js @@ -1,7 +1,7 @@ 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; diff --git a/bigbluebutton-html5/imports/api/slides/server/modifiers/clearSlides.js b/bigbluebutton-html5/imports/api/slides/server/modifiers/clearSlides.js index 868290d952..c20dd62f2d 100755 --- a/bigbluebutton-html5/imports/api/slides/server/modifiers/clearSlides.js +++ b/bigbluebutton-html5/imports/api/slides/server/modifiers/clearSlides.js @@ -3,8 +3,8 @@ import Logger from '/imports/startup/server/logger'; export default function clearSlides(meetingId) { if (meetingId) { - return Slides.remove({ meetingId: meetingId }, Logger.info(`Cleared Slides (${meetingId})`)); - } else { - return Slides.remove({}, Logger.info('Cleared Slides (all)')); + return Slides.remove({ meetingId }, Logger.info(`Cleared Slides (${meetingId})`)); } + + return Slides.remove({}, Logger.info('Cleared Slides (all)')); }; diff --git a/bigbluebutton-html5/server/main.js b/bigbluebutton-html5/server/main.js index 7ce7c8ba59..fbe662aa05 100755 --- a/bigbluebutton-html5/server/main.js +++ b/bigbluebutton-html5/server/main.js @@ -1,11 +1,7 @@ import '/imports/startup/server'; import '/imports/api/chat/server'; -import '/imports/api/cursor/server/publications'; -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/cursor/server'; import '/imports/api/deskshare/server/publications'; import '/imports/api/deskshare/server/modifiers/clearDeskshareCollection';