From 0b2bf8f68b74210561d08d7055e82d3ed1017781 Mon Sep 17 00:00:00 2001 From: Gustavo Trott Date: Thu, 6 Apr 2023 17:43:57 -0300 Subject: [PATCH] Akka-apps will set mobile flag instead of Meteor --- .../ChangeUserMobileFlagReqMsgHdlr.scala | 42 +++++++++++++++++++ .../core/apps/users/UsersApp.scala | 1 + .../voice/UserJoinedVoiceConfEvtMsgHdlr.scala | 1 + .../bigbluebutton/core/models/Users2x.scala | 7 ++++ .../senders/ReceivedJsonMsgHandlerActor.scala | 2 + .../core/running/HandlerHelpers.scala | 1 + .../core/running/MeetingActor.scala | 9 ++-- .../bigbluebutton/core2/AnalyticsActor.scala | 1 + .../core2/testdata/FakeTestData.scala | 2 +- .../common2/msgs/UsersMsgs.scala | 14 +++++++ .../imports/api/users/server/eventHandlers.js | 2 + .../users/server/handlers/changeMobileFlag.js | 13 ++++++ .../api/users/server/methods/setMobileUser.js | 15 +++++-- 13 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ChangeUserMobileFlagReqMsgHdlr.scala create mode 100644 bigbluebutton-html5/imports/api/users/server/handlers/changeMobileFlag.js diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ChangeUserMobileFlagReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ChangeUserMobileFlagReqMsgHdlr.scala new file mode 100644 index 0000000000..0c44be6844 --- /dev/null +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ChangeUserMobileFlagReqMsgHdlr.scala @@ -0,0 +1,42 @@ +package org.bigbluebutton.core.apps.users + +import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.RightsManagementTrait +import org.bigbluebutton.core.models.{ UserState, Users2x } +import org.bigbluebutton.core.running.{ LiveMeeting, OutMsgRouter } + +trait ChangeUserMobileFlagReqMsgHdlr extends RightsManagementTrait { + this: UsersApp => + + val liveMeeting: LiveMeeting + val outGW: OutMsgRouter + + def handleChangeUserMobileFlagReqMsg(msg: ChangeUserMobileFlagReqMsg): Unit = { + log.info("handleChangeUserMobileFlagReqMsg: mobile={} userId={}", msg.body.mobile, msg.body.userId) + + def broadcastUserMobileChanged(user: UserState, mobile: Boolean): Unit = { + val routingChange = Routing.addMsgToClientRouting( + MessageTypes.BROADCAST_TO_MEETING, + liveMeeting.props.meetingProp.intId, user.intId + ) + val envelopeChange = BbbCoreEnvelope(UserMobileFlagChangedEvtMsg.NAME, routingChange) + val headerChange = BbbClientMsgHeader(UserMobileFlagChangedEvtMsg.NAME, liveMeeting.props.meetingProp.intId, + user.intId) + + val bodyChange = UserMobileFlagChangedEvtMsgBody(user.intId, mobile) + val eventChange = UserMobileFlagChangedEvtMsg(headerChange, bodyChange) + val msgEventChange = BbbCommonEnvCoreMsg(envelopeChange, eventChange) + outGW.send(msgEventChange) + } + + for { + user <- Users2x.findWithIntId(liveMeeting.users2x, msg.body.userId) + } yield { + if (user.mobile != msg.body.mobile) { + val userMobile = Users2x.setMobile(liveMeeting.users2x, user) + broadcastUserMobileChanged(userMobile, msg.body.mobile) + } + } + + } +} \ No newline at end of file diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala index 5d597bbfb8..5d821efc35 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala @@ -158,6 +158,7 @@ class UsersApp( with SelectRandomViewerReqMsgHdlr with AssignPresenterReqMsgHdlr with ChangeUserPinStateReqMsgHdlr + with ChangeUserMobileFlagReqMsgHdlr with EjectUserFromMeetingCmdMsgHdlr with EjectUserFromMeetingSysMsgHdlr with MuteUserCmdMsgHdlr { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/voice/UserJoinedVoiceConfEvtMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/voice/UserJoinedVoiceConfEvtMsgHdlr.scala index 6ff90dbaf4..354473b0f2 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/voice/UserJoinedVoiceConfEvtMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/voice/UserJoinedVoiceConfEvtMsgHdlr.scala @@ -50,6 +50,7 @@ trait UserJoinedVoiceConfEvtMsgHdlr extends SystemConfiguration { guestStatus = GuestStatus.WAIT, emoji = "none", pin = false, + mobile = false, presenter = false, locked = MeetingStatus2x.getPermissions(liveMeeting.status).lockOnJoin, avatar = "", diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Users2x.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Users2x.scala index be46b93d75..9f94230fda 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Users2x.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Users2x.scala @@ -107,6 +107,12 @@ object Users2x { newUserState } + def setMobile(users: Users2x, u: UserState): UserState = { + val newUserState = modify(u)(_.mobile).setTo(true) + users.save(newUserState) + newUserState + } + def ejectFromMeeting(users: Users2x, intId: String): Option[UserState] = { for { _ <- users.remove(intId) @@ -354,6 +360,7 @@ case class UserState( role: String, guest: Boolean, pin: Boolean, + mobile: Boolean, authed: Boolean, guestStatus: String, emoji: String, diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/pubsub/senders/ReceivedJsonMsgHandlerActor.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/pubsub/senders/ReceivedJsonMsgHandlerActor.scala index edfee4f9d3..98808f3e90 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/pubsub/senders/ReceivedJsonMsgHandlerActor.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/pubsub/senders/ReceivedJsonMsgHandlerActor.scala @@ -109,6 +109,8 @@ class ReceivedJsonMsgHandlerActor( routeGenericMsg[UserActivitySignCmdMsg](envelope, jsonNode) case ChangeUserPinStateReqMsg.NAME => routeGenericMsg[ChangeUserPinStateReqMsg](envelope, jsonNode) + case ChangeUserMobileFlagReqMsg.NAME => + routeGenericMsg[ChangeUserMobileFlagReqMsg](envelope, jsonNode) case SelectRandomViewerReqMsg.NAME => routeGenericMsg[SelectRandomViewerReqMsg](envelope, jsonNode) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala index be0b615378..857459c85d 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala @@ -63,6 +63,7 @@ trait HandlerHelpers extends SystemConfiguration { guestStatus = regUser.guestStatus, emoji = "none", pin = false, + mobile = false, presenter = false, locked = MeetingStatus2x.getPermissions(liveMeeting.status).lockOnJoin, avatar = regUser.avatarURL, diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/MeetingActor.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/MeetingActor.scala index c7b3032cbd..3c62400cff 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/MeetingActor.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/MeetingActor.scala @@ -384,10 +384,11 @@ class MeetingActor( case m: RecordAndClearPreviousMarkersCmdMsg => state = usersApp.handleRecordAndClearPreviousMarkersCmdMsg(m, state) updateUserLastActivity(m.body.setBy) - case m: GetRecordingStatusReqMsg => usersApp.handleGetRecordingStatusReqMsg(m) - case m: ChangeUserEmojiCmdMsg => handleChangeUserEmojiCmdMsg(m) - case m: SelectRandomViewerReqMsg => usersApp.handleSelectRandomViewerReqMsg(m) - case m: ChangeUserPinStateReqMsg => usersApp.handleChangeUserPinStateReqMsg(m) + case m: GetRecordingStatusReqMsg => usersApp.handleGetRecordingStatusReqMsg(m) + case m: ChangeUserEmojiCmdMsg => handleChangeUserEmojiCmdMsg(m) + case m: SelectRandomViewerReqMsg => usersApp.handleSelectRandomViewerReqMsg(m) + case m: ChangeUserPinStateReqMsg => usersApp.handleChangeUserPinStateReqMsg(m) + case m: ChangeUserMobileFlagReqMsg => usersApp.handleChangeUserMobileFlagReqMsg(m) // Client requested to eject user case m: EjectUserFromMeetingCmdMsg => diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/AnalyticsActor.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/AnalyticsActor.scala index be964dc2eb..5949199738 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/AnalyticsActor.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/AnalyticsActor.scala @@ -77,6 +77,7 @@ class AnalyticsActor(val includeChat: Boolean) extends Actor with ActorLogging { case m: UserDisconnectedFromGlobalAudioMsg => logMessage(msg) case m: AssignPresenterReqMsg => logMessage(msg) case m: ChangeUserPinStateReqMsg => logMessage(msg) + case m: ChangeUserMobileFlagReqMsg => logMessage(msg) case m: ScreenshareRtmpBroadcastStartedVoiceConfEvtMsg => logMessage(msg) case m: ScreenshareRtmpBroadcastStoppedVoiceConfEvtMsg => logMessage(msg) case m: ScreenshareRtmpBroadcastStartedEvtMsg => logMessage(msg) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/testdata/FakeTestData.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/testdata/FakeTestData.scala index a608b54cda..189be4419c 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/testdata/FakeTestData.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/testdata/FakeTestData.scala @@ -67,7 +67,7 @@ trait FakeTestData { def createFakeUser(liveMeeting: LiveMeeting, regUser: RegisteredUser): UserState = { UserState(intId = regUser.id, extId = regUser.externId, name = regUser.name, role = regUser.role, pin = false, - guest = regUser.guest, authed = regUser.authed, guestStatus = regUser.guestStatus, + mobile = false, guest = regUser.guest, authed = regUser.authed, guestStatus = regUser.guestStatus, emoji = "none", locked = false, presenter = false, avatar = regUser.avatarURL, color = "#ff6242", clientType = "unknown", pickExempted = false, userLeftFlag = UserLeftFlag(false, 0)) } diff --git a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMsgs.scala b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMsgs.scala index cc535a9ac2..6736acef1b 100755 --- a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMsgs.scala +++ b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMsgs.scala @@ -200,6 +200,20 @@ object UserEmojiChangedEvtMsg { val NAME = "UserEmojiChangedEvtMsg" } case class UserEmojiChangedEvtMsg(header: BbbClientMsgHeader, body: UserEmojiChangedEvtMsgBody) extends BbbCoreMsg case class UserEmojiChangedEvtMsgBody(userId: String, emoji: String) +/** + * Sent from client about a user mobile flag. + */ +object ChangeUserMobileFlagReqMsg { val NAME = "ChangeUserMobileFlagReqMsg" } +case class ChangeUserMobileFlagReqMsg(header: BbbClientMsgHeader, body: ChangeUserMobileFlagReqMsgBody) extends StandardMsg +case class ChangeUserMobileFlagReqMsgBody(userId: String, mobile: Boolean) + +/** + * Sent to all clients about a user mobile flag. + */ +object UserMobileFlagChangedEvtMsg { val NAME = "UserMobileFlagChangedEvtMsg" } +case class UserMobileFlagChangedEvtMsg(header: BbbClientMsgHeader, body: UserMobileFlagChangedEvtMsgBody) extends BbbCoreMsg +case class UserMobileFlagChangedEvtMsgBody(userId: String, mobile: Boolean) + object AssignPresenterReqMsg { val NAME = "AssignPresenterReqMsg" } case class AssignPresenterReqMsg(header: BbbClientMsgHeader, body: AssignPresenterReqMsgBody) extends StandardMsg case class AssignPresenterReqMsgBody(requesterId: String, newPresenterId: String, newPresenterName: String, assignedBy: String) diff --git a/bigbluebutton-html5/imports/api/users/server/eventHandlers.js b/bigbluebutton-html5/imports/api/users/server/eventHandlers.js index fea9ed8ebf..7891bd0d0e 100644 --- a/bigbluebutton-html5/imports/api/users/server/eventHandlers.js +++ b/bigbluebutton-html5/imports/api/users/server/eventHandlers.js @@ -8,6 +8,7 @@ import handleEmojiStatus from './handlers/emojiStatus'; import handleChangeRole from './handlers/changeRole'; import handleUserPinChanged from './handlers/userPinChanged'; import handleUserInactivityInspect from './handlers/userInactivityInspect'; +import handleChangeMobileFlag from '/imports/api/users/server/handlers/changeMobileFlag'; RedisPubSub.on('PresenterAssignedEvtMsg', handlePresenterAssigned); RedisPubSub.on('UserJoinedMeetingEvtMsg', handleUserJoined); @@ -15,6 +16,7 @@ RedisPubSub.on('UserLeftMeetingEvtMsg', handleRemoveUser); RedisPubSub.on('ValidateAuthTokenRespMsg', handleValidateAuthToken); RedisPubSub.on('UserEmojiChangedEvtMsg', handleEmojiStatus); RedisPubSub.on('UserRoleChangedEvtMsg', handleChangeRole); +RedisPubSub.on('UserMobileFlagChangedEvtMsg', handleChangeMobileFlag); RedisPubSub.on('UserLeftFlagUpdatedEvtMsg', handleUserLeftFlagUpdated); RedisPubSub.on('UserPinStateChangedEvtMsg', handleUserPinChanged); RedisPubSub.on('UserInactivityInspectMsg', handleUserInactivityInspect); diff --git a/bigbluebutton-html5/imports/api/users/server/handlers/changeMobileFlag.js b/bigbluebutton-html5/imports/api/users/server/handlers/changeMobileFlag.js new file mode 100644 index 0000000000..3ac646564c --- /dev/null +++ b/bigbluebutton-html5/imports/api/users/server/handlers/changeMobileFlag.js @@ -0,0 +1,13 @@ +import { check } from 'meteor/check'; +import setMobile from '/imports/api/users/server/modifiers/setMobile'; + +export default async function handleChangeMobileFlag(payload, meetingId) { + check(payload.body, Object); + check(meetingId, String); + + const { userId: requesterUserId, mobile } = payload.body; + + if (mobile) { + await setMobile(meetingId, requesterUserId); + } +} diff --git a/bigbluebutton-html5/imports/api/users/server/methods/setMobileUser.js b/bigbluebutton-html5/imports/api/users/server/methods/setMobileUser.js index fa6dd68dc1..cc3295980e 100644 --- a/bigbluebutton-html5/imports/api/users/server/methods/setMobileUser.js +++ b/bigbluebutton-html5/imports/api/users/server/methods/setMobileUser.js @@ -1,18 +1,27 @@ import { check } from 'meteor/check'; import Logger from '/imports/startup/server/logger'; -import setMobile from '../modifiers/setMobile'; import { extractCredentials } from '/imports/api/common/server/helpers'; +import RedisPubSub from '/imports/startup/server/redis'; -export default function setMobileUser() { +export default async function setMobileUser() { try { + const REDIS_CONFIG = Meteor.settings.private.redis; + const CHANNEL = REDIS_CONFIG.channels.toAkkaApps; + const EVENT_NAME = 'ChangeUserMobileFlagReqMsg'; + const { meetingId, requesterUserId } = extractCredentials(this.userId); check(meetingId, String); check(requesterUserId, String); + const payload = { + userId: requesterUserId, + mobile: true, + }; + Logger.verbose(`Mobile user ${requesterUserId} from meeting ${meetingId}`); - setMobile(meetingId, requesterUserId); + RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); } catch (err) { Logger.error(`Exception while invoking method setMobileUser ${err.stack}`); }