From 5e5abc871d4bda94bb31a208657e90b49abc8e6f Mon Sep 17 00:00:00 2001 From: Anton Georgiev <anto.georgiev@gmail.com> Date: Thu, 2 Nov 2017 18:08:42 -0400 Subject: [PATCH] adapt Polls in akka-apps to work with the default presentation pod only --- .../apps/polls/GetCurrentPollReqMsgHdlr.scala | 7 ++-- .../apps/polls/ShowPollResultReqMsgHdlr.scala | 7 ++-- .../polls/StartCustomPollReqMsgHdlr.scala | 7 ++-- .../core/apps/polls/StartPollReqMsgHdlr.scala | 7 ++-- .../core/apps/polls/StopPollReqMsgHdlr.scala | 13 +++----- .../core/apps/users/UserLeaveReqMsgHdlr.scala | 2 +- .../org/bigbluebutton/core/models/Polls.scala | 32 +++++++++++++------ .../core/models/PresentationPods.scala | 5 +++ .../core/running/MeetingActor.scala | 12 +++---- 9 files changed, 55 insertions(+), 37 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/GetCurrentPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/GetCurrentPollReqMsgHdlr.scala index c17a2d1f71..c92a9ad513 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/GetCurrentPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/GetCurrentPollReqMsgHdlr.scala @@ -3,13 +3,14 @@ package org.bigbluebutton.core.apps.polls import org.bigbluebutton.common2.domain.PollVO import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus +import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.Polls -import org.bigbluebutton.core.running.{ LiveMeeting } +import org.bigbluebutton.core.running.LiveMeeting trait GetCurrentPollReqMsgHdlr { this: PollApp2x => - def handle(msgIn: GetCurrentPollReqMsg, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + def handle(msgIn: GetCurrentPollReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { def broadcastEvent(msg: GetCurrentPollReqMsg, hasPoll: Boolean, pvo: Option[PollVO]): Unit = { val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, liveMeeting.props.meetingProp.intId, msg.header.userId) @@ -22,7 +23,7 @@ trait GetCurrentPollReqMsgHdlr { bus.outGW.send(msgEvent) } - val pollVO = Polls.handleGetCurrentPollReqMsg(msgIn.header.userId, liveMeeting) + val pollVO = Polls.handleGetCurrentPollReqMsg(state, msgIn.header.userId, liveMeeting) pollVO match { case Some(poll) => { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/ShowPollResultReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/ShowPollResultReqMsgHdlr.scala index 1475b61c61..b72e5109e8 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/ShowPollResultReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/ShowPollResultReqMsgHdlr.scala @@ -3,13 +3,14 @@ package org.bigbluebutton.core.apps.polls import org.bigbluebutton.common2.domain.SimplePollResultOutVO import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus +import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.Polls -import org.bigbluebutton.core.running.{ LiveMeeting } +import org.bigbluebutton.core.running.LiveMeeting trait ShowPollResultReqMsgHdlr { this: PollApp2x => - def handle(msg: ShowPollResultReqMsg, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + def handle(msg: ShowPollResultReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { def broadcastEvent(msg: ShowPollResultReqMsg, result: SimplePollResultOutVO, annot: AnnotationVO): Unit = { // PollShowResultEvtMsg @@ -34,7 +35,7 @@ trait ShowPollResultReqMsgHdlr { } for { - (result, annotationProp) <- Polls.handleShowPollResultReqMsg(msg.header.userId, msg.body.pollId, liveMeeting) + (result, annotationProp) <- Polls.handleShowPollResultReqMsg(state, msg.header.userId, msg.body.pollId, liveMeeting) } yield { broadcastEvent(msg, result, annotationProp) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartCustomPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartCustomPollReqMsgHdlr.scala index 6461d164e1..6befa73a5b 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartCustomPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartCustomPollReqMsgHdlr.scala @@ -3,13 +3,14 @@ package org.bigbluebutton.core.apps.polls import org.bigbluebutton.common2.domain.SimplePollOutVO import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus +import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.Polls -import org.bigbluebutton.core.running.{ LiveMeeting } +import org.bigbluebutton.core.running.LiveMeeting trait StartCustomPollReqMsgHdlr { this: PollApp2x => - def handle(msg: StartCustomPollReqMsg, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + def handle(msg: StartCustomPollReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { def broadcastEvent(msg: StartCustomPollReqMsg, poll: SimplePollOutVO): Unit = { val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, liveMeeting.props.meetingProp.intId, msg.header.userId) val envelope = BbbCoreEnvelope(PollStartedEvtMsg.NAME, routing) @@ -22,7 +23,7 @@ trait StartCustomPollReqMsgHdlr { } for { - pvo <- Polls.handleStartCustomPollReqMsg(msg.header.userId, msg.body.pollId, msg.body.pollType, msg.body.answers, liveMeeting) + pvo <- Polls.handleStartCustomPollReqMsg(state, msg.header.userId, msg.body.pollId, msg.body.pollType, msg.body.answers, liveMeeting) } yield { broadcastEvent(msg, pvo) } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartPollReqMsgHdlr.scala index e9e5cb0354..98ccda6cca 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StartPollReqMsgHdlr.scala @@ -3,13 +3,14 @@ package org.bigbluebutton.core.apps.polls import org.bigbluebutton.common2.domain.SimplePollOutVO import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus +import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.Polls -import org.bigbluebutton.core.running.{ LiveMeeting, MeetingActor, OutMsgRouter } +import org.bigbluebutton.core.running.LiveMeeting trait StartPollReqMsgHdlr { this: PollApp2x => - def handle(msg: StartPollReqMsg, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + def handle(msg: StartPollReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { def broadcastEvent(msg: StartPollReqMsg, poll: SimplePollOutVO): Unit = { val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, liveMeeting.props.meetingProp.intId, msg.header.userId) @@ -23,7 +24,7 @@ trait StartPollReqMsgHdlr { } for { - pvo <- Polls.handleStartPollReqMsg(msg.header.userId, msg.body.pollId, msg.body.pollType, liveMeeting) + pvo <- Polls.handleStartPollReqMsg(state, msg.header.userId, msg.body.pollId, msg.body.pollType, liveMeeting) } yield { broadcastEvent(msg, pvo) } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StopPollReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StopPollReqMsgHdlr.scala index f855175395..ffb6b32cf2 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StopPollReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/polls/StopPollReqMsgHdlr.scala @@ -2,6 +2,7 @@ package org.bigbluebutton.core.apps.polls import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus +import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.Polls import org.bigbluebutton.core.running.LiveMeeting @@ -19,17 +20,13 @@ trait StopPollReqMsgHdlr { bus.outGW.send(msgEvent) } - def handle(msg: StopPollReqMsg, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { - for { - stoppedPollId <- Polls.handleStopPollReqMsg(msg.header.userId, liveMeeting) - } yield { - broadcastPollStoppedEvtMsg(msg.header.userId, stoppedPollId, liveMeeting, bus) - } + def handle(msg: StopPollReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + stopPoll(state, msg.header.userId, liveMeeting, bus) } - def stopPoll(requesterId: String, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { + def stopPoll(state: MeetingState2x, requesterId: String, liveMeeting: LiveMeeting, bus: MessageBus): Unit = { for { - stoppedPollId <- Polls.handleStopPollReqMsg(requesterId, liveMeeting) + stoppedPollId <- Polls.handleStopPollReqMsg(state, requesterId, liveMeeting) } yield { broadcastPollStoppedEvtMsg(requesterId, stoppedPollId, liveMeeting, bus) } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala index dc1cba65d2..686cf634d1 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala @@ -40,7 +40,7 @@ trait UserLeaveReqMsgHdlr { ) // request ongoing poll to end - pollApp.stopPoll(u.intId, liveMeeting, msgBus) + pollApp.stopPoll(state, u.intId, liveMeeting, msgBus) } def broadcastEvent(vu: VoiceUserState): Unit = { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala index 70da11e424..d19ffadcac 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Polls.scala @@ -3,6 +3,7 @@ package org.bigbluebutton.core.models import org.bigbluebutton.common2.domain._ import org.bigbluebutton.common2.msgs.AnnotationVO import org.bigbluebutton.core.apps.WhiteboardKeyUtil +import org.bigbluebutton.core.domain.MeetingState2x import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.HashMap @@ -10,7 +11,8 @@ import org.bigbluebutton.core.running.LiveMeeting object Polls { - def handleStartPollReqMsg(userId: String, pollId: String, pollType: String, lm: LiveMeeting): Option[SimplePollOutVO] = { + def handleStartPollReqMsg(state: MeetingState2x, userId: String, pollId: String, pollType: String, + lm: LiveMeeting): Option[SimplePollOutVO] = { def createPoll(pollId: String, numRespondents: Int): Option[Poll] = { for { poll <- PollFactory.createPoll(pollId, pollType, numRespondents, None) @@ -21,7 +23,9 @@ object Polls { } for { - page <- lm.presModel.getCurrentPage() + pod <- state.presentationPodManager.getDefaultPod() + pres <- pod.getCurrentPresentation() + page <- pres.getCurrentPage(pres) pageId: String = if (pollId.contains("deskshare")) "deskshare" else page.id stampedPollId: String = pageId + "/" + System.currentTimeMillis() numRespondents: Int = Users2x.numUsers(lm.users2x) - 1 // subtract the presenter @@ -34,9 +38,11 @@ object Polls { } } - def handleStopPollReqMsg(userId: String, lm: LiveMeeting): Option[String] = { + def handleStopPollReqMsg(state: MeetingState2x, userId: String, lm: LiveMeeting): Option[String] = { for { - page <- lm.presModel.getCurrentPage() + pod <- state.presentationPodManager.getDefaultPod() + pres <- pod.getCurrentPresentation() + page <- pres.getCurrentPage(pres) curPoll <- getRunningPollThatStartsWith(page.id, lm.polls) } yield { stopPoll(curPoll.id, lm.polls) @@ -44,14 +50,16 @@ object Polls { } } - def handleShowPollResultReqMsg(requesterId: String, pollId: String, lm: LiveMeeting): Option[(SimplePollResultOutVO, AnnotationVO)] = { + def handleShowPollResultReqMsg(state: MeetingState2x, requesterId: String, pollId: String, lm: LiveMeeting): Option[(SimplePollResultOutVO, AnnotationVO)] = { def updateWhiteboardAnnotation(annotation: AnnotationVO): AnnotationVO = { lm.wbModel.updateAnnotation(annotation.wbId, annotation.userId, annotation) } def send(poll: SimplePollResultOutVO, shape: scala.collection.immutable.Map[String, Object]): Option[AnnotationVO] = { for { - page <- lm.presModel.getCurrentPage() + pod <- state.presentationPodManager.getDefaultPod() + pres <- pod.getCurrentPresentation() + page <- pres.getCurrentPage(pres) } yield { val pageId = if (poll.id.contains("deskshare")) "deskshare" else page.id val updatedShape = shape + ("whiteboardId" -> pageId) @@ -80,9 +88,11 @@ object Polls { } } - def handleGetCurrentPollReqMsg(requesterId: String, lm: LiveMeeting): Option[PollVO] = { + def handleGetCurrentPollReqMsg(state: MeetingState2x, requesterId: String, lm: LiveMeeting): Option[PollVO] = { val poll = for { - page <- lm.presModel.getCurrentPage() + pod <- state.presentationPodManager.getDefaultPod() + pres <- pod.getCurrentPresentation() + page <- pres.getCurrentPage(pres) curPoll <- getRunningPollThatStartsWith(page.id, lm.polls) } yield curPoll @@ -113,7 +123,7 @@ object Polls { } - def handleStartCustomPollReqMsg(requesterId: String, pollId: String, pollType: String, + def handleStartCustomPollReqMsg(state: MeetingState2x, requesterId: String, pollId: String, pollType: String, answers: Seq[String], lm: LiveMeeting): Option[SimplePollOutVO] = { def createPoll(pollId: String, numRespondents: Int): Option[Poll] = { @@ -126,7 +136,9 @@ object Polls { } for { - page <- lm.presModel.getCurrentPage() + pod <- state.presentationPodManager.getDefaultPod() + pres <- pod.getCurrentPresentation() + page <- pres.getCurrentPage(pres) pageId: String = if (pollId.contains("deskshare")) "deskshare" else page.id stampedPollId: String = pageId + "/" + System.currentTimeMillis() numRespondents: Int = Users2x.numUsers(lm.users2x) - 1 // subtract the presenter diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/PresentationPods.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/PresentationPods.scala index 860ff7c28d..035dcda8b1 100644 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/PresentationPods.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/PresentationPods.scala @@ -35,6 +35,10 @@ case class PresentationInPod(id: String, name: String, current: Boolean = false, } } + def getCurrentPage(pres: PresentationInPod): Option[PageVO] = { + pres.pages.values find (p => p.current) + } + } case class PresentationPod(id: String, ownerId: String, currentPresenter: String, @@ -116,6 +120,7 @@ case class PresentationPodManager(presentationPods: collection.immutable.Map[Str def getNumberOfPods(): Int = presentationPods.size def getPod(podId: String): Option[PresentationPod] = presentationPods.get(podId) + def getDefaultPod(): Option[PresentationPod] = presentationPods.get("DEFAULT_PRESENTATION_POD") def getAllPresentationPodsInMeeting(): Vector[PresentationPod] = presentationPods.values.toVector def updatePresentationPod(presPod: PresentationPod): PresentationPodManager = addPod(presPod) 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 8a58e04838..d36b2aac9a 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 @@ -240,12 +240,12 @@ class MeetingActor( case m: ClientToServerLatencyTracerMsg => handleClientToServerLatencyTracerMsg(m) // Poll - case m: StartPollReqMsg => pollApp.handle(m, liveMeeting, msgBus) - case m: StartCustomPollReqMsg => pollApp.handle(m, liveMeeting, msgBus) - case m: StopPollReqMsg => pollApp.handle(m, liveMeeting, msgBus) - case m: ShowPollResultReqMsg => pollApp.handle(m, liveMeeting, msgBus) + case m: StartPollReqMsg => pollApp.handle(m, state, liveMeeting, msgBus) // passing state but not modifying it + case m: StartCustomPollReqMsg => pollApp.handle(m, state, liveMeeting, msgBus) // passing state but not modifying it + case m: StopPollReqMsg => pollApp.handle(m, state, liveMeeting, msgBus) // passing state but not modifying it + case m: ShowPollResultReqMsg => pollApp.handle(m, state, liveMeeting, msgBus) // passing state but not modifying it case m: HidePollResultReqMsg => pollApp.handle(m, liveMeeting, msgBus) - case m: GetCurrentPollReqMsg => pollApp.handle(m, liveMeeting, msgBus) + case m: GetCurrentPollReqMsg => pollApp.handle(m, state, liveMeeting, msgBus) // passing state but not modifying it case m: RespondToPollReqMsg => pollApp.handle(m, liveMeeting, msgBus) // Breakout @@ -366,7 +366,7 @@ class MeetingActor( def handlePresenterChange(msg: AssignPresenterReqMsg): Unit = { // Stop poll if one is running as presenter left - pollApp.stopPoll(msg.header.userId, liveMeeting, msgBus) + pollApp.stopPoll(state, msg.header.userId, liveMeeting, msgBus) // switch user presenter status for old and new presenter usersApp.handleAssignPresenterReqMsg(msg) -- GitLab