From d07bca00c99093ae64860bf731d4a6c8e7d307e2 Mon Sep 17 00:00:00 2001 From: Oswaldo Acauan Date: Thu, 23 Feb 2017 18:52:50 +0000 Subject: [PATCH] Refactor handlers inside /phone to the /user folder --- .../users/server/handlers/listeningOnly.js | 36 +++++++++++++++++++ .../api/users/server/handlers/voiceUpdate.js | 20 +++++++++++ .../server/modifiers/lockAllViewersMic.js | 24 +++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 bigbluebutton-html5/imports/api/users/server/handlers/listeningOnly.js create mode 100644 bigbluebutton-html5/imports/api/users/server/handlers/voiceUpdate.js create mode 100755 bigbluebutton-html5/imports/api/users/server/modifiers/lockAllViewersMic.js diff --git a/bigbluebutton-html5/imports/api/users/server/handlers/listeningOnly.js b/bigbluebutton-html5/imports/api/users/server/handlers/listeningOnly.js new file mode 100644 index 0000000000..c6fc676c69 --- /dev/null +++ b/bigbluebutton-html5/imports/api/users/server/handlers/listeningOnly.js @@ -0,0 +1,36 @@ +import { check } from 'meteor/check'; +import Logger from '/imports/startup/server/logger'; +import Users from '/imports/api/users'; + +export default function handleListeningOnly({ payload }) { + const meetingId = payload.meeting_id; + const userId = payload.userid; + const listenOnly = payload.listen_only; + + check(meetingId, String); + check(userId, String); + check(listenOnly, String); + + const selector = { + meetingId, + userId, + }; + + const modifier = { + $set: { + 'user.listenOnly': listenOnly, + }, + }; + + const cb = (err, numChanged) => { + if (err) { + return Logger.error(`Assigning user listen only status: ${err}`); + } + + if (numChanged) { + return Logger.info(`Assigned listen only status '${listenOnly}' user=${userId} meeting=${meetingId}`); + } + }; + + return Users.update(selector, modifier, cb); +}; diff --git a/bigbluebutton-html5/imports/api/users/server/handlers/voiceUpdate.js b/bigbluebutton-html5/imports/api/users/server/handlers/voiceUpdate.js new file mode 100644 index 0000000000..5d677f69d2 --- /dev/null +++ b/bigbluebutton-html5/imports/api/users/server/handlers/voiceUpdate.js @@ -0,0 +1,20 @@ +import { check } from 'meteor/check'; +import Logger from '/imports/startup/server/logger'; + +import updateVoiceUser from '../modifiers/updateVoiceUser'; + +export default function handleVoiceUpdate({ payload }) { + const meetingId = payload.meeting_id; + const user = payload.user; + + check(meetingId, String); + check(user, Object); + + const voiceUser = user.voiceUser; + check(voiceUser, Object); + + const userId = voiceUser.web_userid; + check(userId, Object); + + return updateVoiceUser(meetingId, userId, voiceUser); +}; diff --git a/bigbluebutton-html5/imports/api/users/server/modifiers/lockAllViewersMic.js b/bigbluebutton-html5/imports/api/users/server/modifiers/lockAllViewersMic.js new file mode 100755 index 0000000000..6f441db686 --- /dev/null +++ b/bigbluebutton-html5/imports/api/users/server/modifiers/lockAllViewersMic.js @@ -0,0 +1,24 @@ +import { check } from 'meteor/check'; +import Logger from '/imports/startup/server/logger'; + +import Users from '/imports/api/users'; + +export default function lockAllViewersMic(meetingId) { + const selector = { + meetingId, + 'user.role': 'VIEWER', + 'user.listenOnly': false, + 'user.locked': true, + 'user.voiceUser.joined': true, + 'user.voiceUser.muted': false, + }; + + const usersToMute = Users.find(selector).fetch(); + + usersToMute.forEach(user => + muteToggle({ + meetingId, + requesterUserId: user.userId, + }, userId, true) + ); +};