From 86d3e27d474040151aa7e24d1bdec0d4d1762df7 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 3 Jul 2017 12:05:35 -0300 Subject: [PATCH] Merged info with anton's branch --- .../api/2.0/meetings/server/eventHandlers.js | 17 ++-------- .../server/handlers/getAllMeetings.js | 10 ++++++ .../2.0/presentations/server/eventHandlers.js | 6 +--- .../server/handlers/presentationInfoReply.js | 11 +++++-- .../2.0/presentations/server/publishers.js | 2 +- .../api/2.0/users/server/eventHandlers.js | 2 ++ .../api/2.0/users/server/handlers/getUsers.js | 32 +++++++++++++++++++ .../2.0/users/server/modifiers/clearUsers.js | 10 ++++++ .../imports/api/common/server/helpers.js | 4 +-- .../imports/startup/server/redis2x.js | 3 +- 10 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 bigbluebutton-html5/imports/api/2.0/meetings/server/handlers/getAllMeetings.js create mode 100644 bigbluebutton-html5/imports/api/2.0/users/server/handlers/getUsers.js create mode 100755 bigbluebutton-html5/imports/api/2.0/users/server/modifiers/clearUsers.js diff --git a/bigbluebutton-html5/imports/api/2.0/meetings/server/eventHandlers.js b/bigbluebutton-html5/imports/api/2.0/meetings/server/eventHandlers.js index 5249e2648e..10180961ee 100644 --- a/bigbluebutton-html5/imports/api/2.0/meetings/server/eventHandlers.js +++ b/bigbluebutton-html5/imports/api/2.0/meetings/server/eventHandlers.js @@ -1,20 +1,7 @@ import RedisPubSub from '/imports/startup/server/redis2x'; -// import handleMeetingDestruction from './handlers/meetingDestruction'; -// import handleRecordingStatusChange from './handlers/recordingStatusChange'; -// import handlePermissionSettingsChange from './handlers/permissionSettingsChange'; import handleMeetingCreation from './handlers/meetingCreation'; -// import handleGetAllMeetings from './handlers/getAllMeetings'; -// import handleStunTurnReply from './handlers/stunTurnReply'; - -// RedisPubSub.on('meeting_destroyed_event', handleMeetingDestruction); -// RedisPubSub.on('meeting_ended_message', handleMeetingDestruction); -// RedisPubSub.on('end_and_kick_all_message', handleMeetingDestruction); -// RedisPubSub.on('disconnect_all_users_message', handleMeetingDestruction); -// RedisPubSub.on('recording_status_changed_message', handleRecordingStatusChange); -// RedisPubSub.on('new_permission_settings', handlePermissionSettingsChange); -// RedisPubSub.on('meeting_created_message', handleMeetingCreation); -// RedisPubSub.on('get_all_meetings_reply_message', handleGetAllMeetings); -// RedisPubSub.on('send_stun_turn_info_reply_message', handleStunTurnReply); +import handleGetAllMeetings from './handlers/getAllMeetings'; // 2x RedisPubSub.on('MeetingCreatedEvtMsg', handleMeetingCreation); +RedisPubSub.on('SyncGetMeetingInfoRespMsg', handleGetAllMeetings); diff --git a/bigbluebutton-html5/imports/api/2.0/meetings/server/handlers/getAllMeetings.js b/bigbluebutton-html5/imports/api/2.0/meetings/server/handlers/getAllMeetings.js new file mode 100644 index 0000000000..15c5530a89 --- /dev/null +++ b/bigbluebutton-html5/imports/api/2.0/meetings/server/handlers/getAllMeetings.js @@ -0,0 +1,10 @@ +import { inReplyToHTML5Client } from '/imports/api/common/server/helpers'; +import handleMeetingCreation from './meetingCreation'; + +export default function handleGetAllMeetings({ envelope, body }) { + if (!inReplyToHTML5Client(envelope)) { + return; + } + + return handleMeetingCreation({ body }); +} diff --git a/bigbluebutton-html5/imports/api/2.0/presentations/server/eventHandlers.js b/bigbluebutton-html5/imports/api/2.0/presentations/server/eventHandlers.js index eaa8d1d826..293ad83707 100644 --- a/bigbluebutton-html5/imports/api/2.0/presentations/server/eventHandlers.js +++ b/bigbluebutton-html5/imports/api/2.0/presentations/server/eventHandlers.js @@ -1,10 +1,6 @@ import RedisPubSub from '/imports/startup/server/redis2x'; -// import handlePresentationRemove from './handlers/presentationRemove'; import handlePresentationChange from './handlers/presentationChange'; import handlePresentationInfoReply from './handlers/presentationInfoReply'; -// RedisPubSub.on('presentation_removed_message', handlePresentationRemove); -RedisPubSub.on('NewPresentationEvtMsg', handlePresentationChange); -// RedisPubSub.on('get_presentation_info_reply', handlePresentationInfoReply); - RedisPubSub.on('SyncGetPresentationInfoRespMsg', handlePresentationInfoReply); +RedisPubSub.on('NewPresentationEvtMsg', handlePresentationChange); diff --git a/bigbluebutton-html5/imports/api/2.0/presentations/server/handlers/presentationInfoReply.js b/bigbluebutton-html5/imports/api/2.0/presentations/server/handlers/presentationInfoReply.js index 42d366b16f..6ee1a89dd0 100644 --- a/bigbluebutton-html5/imports/api/2.0/presentations/server/handlers/presentationInfoReply.js +++ b/bigbluebutton-html5/imports/api/2.0/presentations/server/handlers/presentationInfoReply.js @@ -1,15 +1,22 @@ import { check } from 'meteor/check'; import Presentations from '/imports/api/2.0/presentations'; +import { inReplyToHTML5Client } from '/imports/api/common/server/helpers'; import addPresentation from '../modifiers/addPresentation'; import removePresentation from '../modifiers/removePresentation'; -export default function handlePresentationInfoReply({ body }, meetingId) { +export default function handlePresentationInfoReply({ envelope, body }, meetingId) { + if (!inReplyToHTML5Client(envelope)) { + return; + } + const presentations = body.presentations; + check(meetingId, String); check(presentations, Array); - const presentationsIds = presentations.map(_ => _.id); + const presentationsIds = presentations.map(presentation => presentation.id); + const presentationsToRemove = Presentations.find({ meetingId, 'presentation.id': { $nin: presentationsIds }, diff --git a/bigbluebutton-html5/imports/api/2.0/presentations/server/publishers.js b/bigbluebutton-html5/imports/api/2.0/presentations/server/publishers.js index 11f12a6f31..7852e78adf 100755 --- a/bigbluebutton-html5/imports/api/2.0/presentations/server/publishers.js +++ b/bigbluebutton-html5/imports/api/2.0/presentations/server/publishers.js @@ -11,7 +11,7 @@ function presentations(credentials) { check(requesterUserId, String); check(requesterToken, String); - Logger.info(`Publishing Presentations for ${meetingId} ${requesterUserId} ${requesterToken}`); + Logger.info(`Publishing Presentations2x for ${meetingId} ${requesterUserId} ${requesterToken}`); return Presentations.find({ meetingId }); } diff --git a/bigbluebutton-html5/imports/api/2.0/users/server/eventHandlers.js b/bigbluebutton-html5/imports/api/2.0/users/server/eventHandlers.js index dee6032391..6bb849ce15 100644 --- a/bigbluebutton-html5/imports/api/2.0/users/server/eventHandlers.js +++ b/bigbluebutton-html5/imports/api/2.0/users/server/eventHandlers.js @@ -5,6 +5,7 @@ import handleValidateAuthToken from './handlers/validateAuthToken'; import handleVoiceUpdate from './handlers/voiceUpdate'; import handlePresenterAssigned from './handlers/presenterAssigned'; import handleEmojiStatus from './handlers/emojiStatus'; +import handleGetUsers from './handlers/getUsers'; RedisPubSub.on('PresenterAssignedEvtMsg', handlePresenterAssigned); RedisPubSub.on('UserJoinedMeetingEvtMsg', handleUserJoined); @@ -13,3 +14,4 @@ RedisPubSub.on('UserLeftVoiceConfToClientEvtMsg', handleVoiceUpdate); RedisPubSub.on('UserJoinedVoiceConfToClientEvtMsg', handleVoiceUpdate); RedisPubSub.on('ValidateAuthTokenRespMsg', handleValidateAuthToken); RedisPubSub.on('UserEmojiChangedEvtMsg', handleEmojiStatus); +RedisPubSub.on('SyncGetUsersMeetingRespMsg', handleGetUsers); diff --git a/bigbluebutton-html5/imports/api/2.0/users/server/handlers/getUsers.js b/bigbluebutton-html5/imports/api/2.0/users/server/handlers/getUsers.js new file mode 100644 index 0000000000..bf8d3d005d --- /dev/null +++ b/bigbluebutton-html5/imports/api/2.0/users/server/handlers/getUsers.js @@ -0,0 +1,32 @@ +import { check } from 'meteor/check'; +import Logger from '/imports/startup/server/logger'; +import Users from '/imports/api/2.0/users/'; +import addUser from '../modifiers/addUser'; +import removeUser from '../modifiers/removeUser'; +import { inReplyToHTML5Client } from '/imports/api/common/server/helpers'; + +export default function handleGetUsers({ envelope, body }, meetingId) { + if (!inReplyToHTML5Client(envelope)) { + return; + } + const { users } = body; + + check(meetingId, String); + check(users, Array); + + const usersIds = users.map(m => m.intId); + + const usersToRemove = Users.find({ + meetingId, + userId: { $nin: usersIds }, + }).fetch(); + + usersToRemove.forEach(user => removeUser(meetingId, user.userId)); + + const usersAdded = []; + users.forEach((user) => { + usersAdded.push(addUser(meetingId, user)); + }); + + return usersAdded; +} diff --git a/bigbluebutton-html5/imports/api/2.0/users/server/modifiers/clearUsers.js b/bigbluebutton-html5/imports/api/2.0/users/server/modifiers/clearUsers.js new file mode 100755 index 0000000000..b1c075e3fc --- /dev/null +++ b/bigbluebutton-html5/imports/api/2.0/users/server/modifiers/clearUsers.js @@ -0,0 +1,10 @@ +import Users from './../../'; +import Logger from '/imports/startup/server/logger'; + +export default function clearUsers(meetingId) { + if (meetingId) { + return Users.remove({ meetingId }, Logger.info(`Cleared Users (${meetingId})`)); + } + + return Users.remove({}, Logger.info('Cleared Users (all)')); +} diff --git a/bigbluebutton-html5/imports/api/common/server/helpers.js b/bigbluebutton-html5/imports/api/common/server/helpers.js index 0d6100620c..9d65f301a6 100755 --- a/bigbluebutton-html5/imports/api/common/server/helpers.js +++ b/bigbluebutton-html5/imports/api/common/server/helpers.js @@ -35,8 +35,6 @@ export const translateHTML5ToFlash = function (message) { return result; }; -// when requesting for history information we pass this made up requesterID -// We want to handle only the reports we requested export const inReplyToHTML5Client = function (arg) { - return arg.payload.requester_id === 'nodeJSapp'; + return arg.routing.userId === 'nodeJSapp'; }; diff --git a/bigbluebutton-html5/imports/startup/server/redis2x.js b/bigbluebutton-html5/imports/startup/server/redis2x.js index 260960bce9..0ee064caa1 100644 --- a/bigbluebutton-html5/imports/startup/server/redis2x.js +++ b/bigbluebutton-html5/imports/startup/server/redis2x.js @@ -109,6 +109,7 @@ class RedisPubSub2x { handleTask(data, next) { const { header } = data.parsedMessage.core; const { body } = data.parsedMessage.core; + const { envelope } = data.parsedMessage; const eventName = header.name; const meetingId = header.meetingId; @@ -118,7 +119,7 @@ class RedisPubSub2x { try { this._debug(`${eventName} emitted`); return this.emitter - .emitAsync(eventName, { header, body }, meetingId) + .emitAsync(eventName, { envelope, header, body }, meetingId) .then((_) => { this._debug(`${eventName} completed`); return next();