work on maintaining correct state (current presentation in pod)

This commit is contained in:
Anton Georgiev 2017-10-27 19:17:50 -04:00
parent 1efe354031
commit d38a05105c
7 changed files with 114 additions and 69 deletions

View File

@ -60,8 +60,13 @@ object PresentationPodsApp {
PresentationVO(pres.id, pres.name, pres.current, pres.pages.values.toVector, pres.downloadable)
}
def setCurrentPresentationInPod(pod: PresentationPod, nextCurrentPresId: String): Option[PresentationPod] = {
pod.setCurrentPresentation(nextCurrentPresId)
def setCurrentPresentationInPod(state: MeetingState2x, podId: String, nextCurrentPresId: String): Option[PresentationPod] = {
for {
pod <- getPresentationPod(state, podId)
updatedPod <- pod.setCurrentPresentation(nextCurrentPresId)
} yield {
updatedPod
}
}
// add ownerId to default presentation pod -- in some cases we add it before first user is available

View File

@ -28,20 +28,20 @@ trait SetCurrentPresentationPubMsgHdlr {
val presId = msg.body.presentationId
val newState = for {
pod <- PresentationPodsApp.getPresentationPod(state, podId)
// presentation <- setCurrentPresentation(liveMeeting, pod.id, presId)
updatedPod <- PresentationPodsApp.setCurrentPresentationInPod(state, podId, presId)
} yield {
// unset old current
PresentationPodsApp.getPresentationPod(state, podId)
// TODO
// set new current
// TODO
broadcastSetCurrentPresentationEvent(podId, msg.header.userId, presId)
log.warning("_____ SetCurrentPresentationPubMsgHdlr _____________________~~~~~_________" + state.presentationPodManager.printPods())
val pods = state.presentationPodManager.addPod(updatedPod)
log.warning("_____ SetCurrentPresentationPubMsgHdlr _____________________~~~~~_________" + pods.printPods())
state.update(pods)
}
newState match {
case Some(ns) => ns
case None => state
}
state
}
}

View File

@ -40,16 +40,8 @@ case class PresentationInPod(id: String, name: String, current: Boolean = false,
case class PresentationPod(id: String, ownerId: String, currentPresenter: String,
presentations: collection.immutable.Map[String, PresentationInPod]) {
def addPresentation(presentation: PresentationInPod): PresentationPod = {
println(s" 1 PresentationPods::addPresentation ${presentation.id} ")
println(s" 1 PresentationPods::addPresentation ${presentation.id} presName=${presentation.name} current=${presentation.current} ")
copy(presentations = presentations + (presentation.id -> presentation))
// for {
// nextPresentation <- setCurrentPresentation(presentation.id)
// } yield {
// println(s" 2 PresentationPods::addPresentation ${nextPresentation.id} ")
// copy(presentations = presentations + (nextPresentation.id -> nextPresentation))
// }
// //Some(copy(presentations = presentations + (presentation.id -> presentation)))
// // setCurrentPresentation(presentation.id)
}
def removePresentation(id: String): PresentationPod = copy(presentations = presentations - id)
@ -61,22 +53,27 @@ case class PresentationPod(id: String, ownerId: String, currentPresenter: String
def getPresentation(presentationId: String): Option[PresentationInPod] =
presentations.values find (p => p.id == presentationId)
def setCurrentPresentation(presId: String): Option[PresentationPod] = { // copy(currentPresenter = userId) // ****
def setCurrentPresentation(presId: String): Option[PresentationPod] = {
var tempPod: PresentationPod = this
presentations.values foreach (curPres => { // unset previous current presentation
if (curPres.id != presId) {
val newPres = curPres.copy(current = false)
addPresentation(newPres)
println(s" ____PresentationPod::setCurrentPresentation presId=${newPres.id} presName=${newPres.name}" +
s" current=${newPres.current}")
tempPod = tempPod.addPresentation(newPres)
}
})
presentations.get(presId) match { // set new current presentation
case Some(pres) =>
val cp = pres.copy(current = true)
Some(addPresentation(cp))
// Some(cp)
// println(s" ____PresentationPod::setCurrentPresentation presId=${newPres.id} presName=${newPres.name} " +
// s" current=${newPres.current}")
tempPod = tempPod.addPresentation(cp)
case None => None
}
Some(tempPod)
}
def setCurrentPage(presentationId: String, pageId: String): Option[PresentationPod] = {
@ -106,7 +103,7 @@ case class PresentationPod(id: String, ownerId: String, currentPresenter: String
def printPod(): String = {
val b = s"printPod (${presentations.values.size}):"
var d = ""
presentations.values.foreach(p => d += s"PRES_ID=${p.id} NAME=${p.name} CURRENT=${p.current}\n")
presentations.values.foreach(p => d += s"\nPRES_ID=${p.id} NAME=${p.name} CURRENT=${p.current}\n")
b.concat(s"PODID=$id OWNERID=$ownerId CURRENTPRESENTER=$currentPresenter PRESENTATIONS={{{$d}}}\n")
}
}
@ -130,9 +127,6 @@ case class PresentationPodManager(presentationPods: collection.immutable.Map[Str
println(s"\n\n------- addPresentationToPod ${pres.name} + ${pres.current} before\n")
val updatedManager = for {
pod <- getPod(podId)
// updatedPod <- pod.addPresentation(pres)
// currentPresPod <- pod.setCurrentPresentation(updatedPod.id)
//podWithAddedPresentation <- pod.addPresentation(pres)
} yield {
println(s"\n\n------- addPresentationToPod ${pres.name} + ${pres.current} after\n")
updatePresentationPod(pod.addPresentation(pres))

View File

@ -19,10 +19,10 @@
package org.bigbluebutton.modules.present.managers
{
import com.asfusion.mate.events.Dispatcher;
import flash.display.DisplayObject;
import flash.geom.Point;
import mx.core.FlexGlobals;
import mx.collections.ArrayCollection;
@ -32,12 +32,10 @@ package org.bigbluebutton.modules.present.managers
import org.bigbluebutton.common.events.CloseWindowEvent;
import org.bigbluebutton.core.Options;
import org.bigbluebutton.core.PopUpUtil;
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.modules.present.events.ExportEvent;
import org.bigbluebutton.modules.present.events.PresentModuleEvent;
import org.bigbluebutton.modules.present.events.UploadEvent;
import org.bigbluebutton.modules.present.events.NewPresentationPodCreated;
import org.bigbluebutton.modules.present.events.RequestNewPresentationPodEvent;
import org.bigbluebutton.modules.present.events.PresentationPodRemoved;
import org.bigbluebutton.modules.present.events.RequestAllPodsEvent;
import org.bigbluebutton.modules.present.events.GetAllPodsRespEvent;
@ -48,19 +46,17 @@ package org.bigbluebutton.modules.present.managers
import org.bigbluebutton.modules.present.ui.views.FileUploadWindow;
import org.bigbluebutton.modules.present.ui.views.PresentationWindow;
public class PresentManager
{
private var globalDispatcher:Dispatcher;
private var windows: Array = [];
private var podsManager: PresentationPodManager;
public function PresentManager() {
globalDispatcher = new Dispatcher();
podsManager = PresentationPodManager.getInstance();
}
public function handleStartModuleEvent(e:PresentModuleEvent):void{
if (windows.length >= 1) {
return;
@ -74,30 +70,37 @@ package org.bigbluebutton.modules.present.managers
var podId: String = e.podId;
var ownerId: String = e.ownerId;
if(!windows.hasOwnProperty(podId)) {
var newWindow:PresentationWindow = new PresentationWindow();
newWindow.onPodCreated(podId, ownerId);
var presentOptions:PresentOptions = Options.getOptions(PresentOptions) as PresentOptions;
newWindow.visible = true; // TODO
// newWindow.visible = presentOptions.showPresentWindow;
newWindow.showControls = presentOptions.showWindowControls;
windows[podId] = newWindow;
var openEvent:OpenWindowEvent = new OpenWindowEvent(OpenWindowEvent.OPEN_WINDOW_EVENT);
openEvent.window = newWindow;
globalDispatcher.dispatchEvent(openEvent);
podsManager.handleAddPresentationPod(podId, ownerId);
if(windows.hasOwnProperty(podId)) {
// remove pod and replace with the updated version
handlePresentationPodRemovedHelper(podId, ownerId);
}
var newWindow:PresentationWindow = new PresentationWindow();
newWindow.onPodCreated(podId, ownerId);
var presentOptions:PresentOptions = Options.getOptions(PresentOptions) as PresentOptions;
newWindow.visible = true; // TODO
// newWindow.visible = presentOptions.showPresentWindow;
newWindow.showControls = presentOptions.showWindowControls;
windows[podId] = newWindow;
var openEvent:OpenWindowEvent = new OpenWindowEvent(OpenWindowEvent.OPEN_WINDOW_EVENT);
openEvent.window = newWindow;
globalDispatcher.dispatchEvent(openEvent);
podsManager.handleAddPresentationPod(podId, ownerId);
}
public function handlePresentationPodRemoved(e: PresentationPodRemoved): void {
var podId: String = e.podId;
var ownerId: String = e.ownerId;
podsManager.handlePresentationPodRemoved(podId, ownerId); // GOOD
handlePresentationPodRemovedHelper(podId, ownerId);
}
private function handlePresentationPodRemovedHelper(podId: String, ownerId: String): void {
podsManager.handlePresentationPodRemoved(podId, ownerId);
var destroyWindow:PresentationWindow = windows[podId];
if (destroyWindow != null) {
@ -178,5 +181,8 @@ package org.bigbluebutton.modules.present.managers
PopUpUtil.removePopUp(FileExportWindow);
}
// public function handleSetPresenterInPodRespEvent(event: SetPresenterInPodRespEvent): void {
//
// }
}
}

View File

@ -5,6 +5,7 @@ package org.bigbluebutton.modules.present.model
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getClassLogger;
import org.bigbluebutton.modules.present.services.messages.PageChangeVO;
import org.bigbluebutton.main.api.JSLog;
public class PresentationModel
{
@ -30,6 +31,24 @@ package org.bigbluebutton.modules.present.model
_ownerId = ownerId;
}
private function whichPageIsCurrent(presId: String): String {
var result: String = "[";
var pres:Presentation = getPresentation(presId);
if (pres == null) {
} else {
var curPage: Page = pres.getCurrentPage();
result = result + curPage.num;
}
return result + "]";
}
public function printPresentations(calledFrom: String): void {
for (var i:int = 0; i < _presentations.length; i++) {
var pres: Presentation = _presentations.getItemAt(i) as Presentation;
JSLog.warn("2001 " + calledFrom +" " + i + " " + pres.name + " " + pres.id + " " + pres.current.toString() + " " + whichPageIsCurrent(pres.id) , {});
}
}
// /**
// * Return the single instance of the PresentationModel class
// */
@ -50,7 +69,9 @@ package org.bigbluebutton.modules.present.model
}
public function addPresentation(p: Presentation):void {
printPresentations("PresentationModel::addPresentation bef total=" + _presentations.length);
_presentations.addItem(p);
printPresentations("PresentationModel::addPresentation aft total=" + _presentations.length);
}
public function removePresentation(presId:String):Presentation {
@ -205,5 +226,3 @@ package org.bigbluebutton.modules.present.model
}
}
}
class SingletonEnforcer{}

View File

@ -18,24 +18,25 @@ package org.bigbluebutton.modules.present.services
import org.bigbluebutton.modules.present.services.messages.PageVO;
import org.bigbluebutton.modules.present.services.messages.PresentationVO;
import org.bigbluebutton.modules.present.services.messaging.MessageReceiver;
import org.bigbluebutton.modules.present.services.messaging.MessageSender;
import org.bigbluebutton.main.api.JSLog;
public class PresentationService
{
private static const LOGGER:ILogger = getClassLogger(PresentationService);
private static const NUM_PRELOAD:uint = 3;
private var podManager: PresentationPodManager;
private var sender:MessageSender;
private var receiver:MessageReceiver;
private var dispatcher:Dispatcher;
public function PresentationService() {
podManager = PresentationPodManager.getInstance();
podManager.setPresentationService(this);
receiver = new MessageReceiver(this);
dispatcher = new Dispatcher();
}
public function pageChanged(podId: String, pageId:String):void {
podManager.getPod(podId).printPresentations("PresentationService::pageChanged bef");
var np: Page = podManager.getPod(podId).getPage(pageId);
if (np != null) {
var oldPage: Page = podManager.getPod(podId).getCurrentPage();
@ -44,7 +45,8 @@ package org.bigbluebutton.modules.present.services
np.current = true;
// trace(LOG + "Sending page changed event. page [" + np.id + "] oldpage current=[" + oldPage.current + "] newPage current=[" + np.current + "]");
var changePageCommand: ChangePageCommand = new ChangePageCommand(podId, np.id, NUM_PRELOAD);
dispatcher.dispatchEvent(changePageCommand);
dispatcher.dispatchEvent(changePageCommand);
podManager.getPod(podId).printPresentations("PresentationService::pageChanged aft");
}
}
@ -79,11 +81,16 @@ package org.bigbluebutton.modules.present.services
public function addPresentation(podId: String, pres:PresentationVO):void {
var presentation:Presentation = presentationVOToPresentation(pres);
JSLog.warn("__ PresentationService::addPresentation: " + presentation.id, {});
podManager.getPod(podId).addPresentation(presentation);
LOGGER.debug("Added new presentation [{0}]", [presentation.id]);
if (presentation.current) {
LOGGER.debug("Making presentation [{0}] current [{1}]", [presentation.id, presentation.current]);
JSLog.warn("__ PresentationService::addPresentation: YES presentation was current. displaying "
+ presentation.name + " in " + podId, {});
LOGGER.debug("Making presentation [{0}] current [{1}]", [presentation.id, presentation.current]);
JSLog.debug("Making presentation " + presentation.id + " current " , presentation.current);
var event: PresentationChangedEvent = new PresentationChangedEvent(podId, pres.id);
dispatcher.dispatchEvent(event);
@ -93,9 +100,13 @@ package org.bigbluebutton.modules.present.services
dispatcher.dispatchEvent(changePageCommand);
LOGGER.debug("Sending page moved event to position page [{0}] current=[{1}]", [curPage.id, curPage.current]);
JSLog.debug("Sending page moved event to position page " + curPage.id + " current=", curPage.current);
var pageChangedEvent: PageChangedEvent = new PageChangedEvent(podId, curPage.id);
dispatcher.dispatchEvent(pageChangedEvent);
}
} else {
JSLog.warn("__ PresentationService::addPresentation: presentation was NOT current. not displaying "
+ presentation.name + " in " + podId, {});
}
}
@ -116,17 +127,24 @@ package org.bigbluebutton.modules.present.services
// We've switched presentations. Mark the old presentation as not current.
var curPres:Presentation = podManager.getPod(podId).getCurrentPresentation();
if (curPres != null) {
JSLog.debug("300005a " + curPres.name , curPres);
curPres.current = false;
JSLog.debug("300005b " + curPres.name , curPres);
} else {
LOGGER.debug("No previous active presentation.");
JSLog.debug("No previous active presentation.", {});
}
podManager.getPod(podId).printPresentations("PresentationService::changeCurrentPresentation bef");
var newPres:Presentation = podManager.getPod(podId).getPresentation(presentationId);
if (newPres != null) {
LOGGER.debug("Making presentation [{0}] the active presentation.", [presentationId]);
JSLog.debug("Making presentation " + presentationId + " the active presentation.", {});
newPres.current = true;
podManager.getPod(podId).printPresentations("PresentationService::changeCurrentPresentation aft");
var event: PresentationChangedEvent = new PresentationChangedEvent(podId, presentationId);
dispatcher.dispatchEvent(event);
@ -137,6 +155,7 @@ package org.bigbluebutton.modules.present.services
}
} else {
LOGGER.debug("Could not find presentation to make current. id="+presentationId);
JSLog.debug("Could not find presentation to make current. id="+presentationId, {});
}
}

View File

@ -91,8 +91,11 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import org.bigbluebutton.core.Options;
import org.bigbluebutton.core.PopUpUtil;
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.main.api.JSLog;
import org.bigbluebutton.main.events.MadePresenterEvent;
import org.bigbluebutton.main.events.ShortcutEvent;
import org.bigbluebutton.main.model.users.events.UserAddedToPresenterGroupEvent;
import org.bigbluebutton.main.model.users.events.UserRemovedFromPresenterGroupEvent;
import org.bigbluebutton.main.views.MainCanvas;
import org.bigbluebutton.modules.polling.events.PollShowResultEvent;
import org.bigbluebutton.modules.polling.events.PollStartedEvent;
@ -102,22 +105,20 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import org.bigbluebutton.modules.polling.views.PollChoicesModal;
import org.bigbluebutton.modules.polling.views.PollResultsModal;
import org.bigbluebutton.modules.present.commands.GoToNextPageCommand;
import org.bigbluebutton.modules.present.commands.GoToPrevPageCommand;
import org.bigbluebutton.modules.present.commands.GoToPageLocalCommand;
import org.bigbluebutton.modules.present.commands.GoToPageCommand;
import org.bigbluebutton.modules.present.commands.GoToPageLocalCommand;
import org.bigbluebutton.modules.present.commands.GoToPrevPageCommand;
import org.bigbluebutton.modules.present.events.DisplaySlideEvent;
import org.bigbluebutton.modules.present.events.DownloadEvent;
import org.bigbluebutton.modules.present.events.ExportEvent;
import org.bigbluebutton.modules.present.events.PresentationChangedEvent;
import org.bigbluebutton.modules.present.events.PresenterCommands;
import org.bigbluebutton.modules.present.events.RemovePresentationEvent;
import org.bigbluebutton.modules.present.events.UploadEvent;
import org.bigbluebutton.modules.present.events.RequestNewPresentationPodEvent;
import org.bigbluebutton.modules.present.events.RequestClosePresentationPodEvent;
import org.bigbluebutton.modules.present.events.SetPresenterInPodRespEvent;
import org.bigbluebutton.modules.present.events.RequestNewPresentationPodEvent;
import org.bigbluebutton.modules.present.events.SetPresenterInPodReqEvent;
import org.bigbluebutton.main.model.users.events.UserAddedToPresenterGroupEvent;
import org.bigbluebutton.main.model.users.events.UserRemovedFromPresenterGroupEvent;
import org.bigbluebutton.modules.present.events.SetPresenterInPodRespEvent;
import org.bigbluebutton.modules.present.events.UploadEvent;
import org.bigbluebutton.modules.present.model.Page;
import org.bigbluebutton.modules.present.model.PresentOptions;
import org.bigbluebutton.modules.present.model.PresentationModel;
@ -127,7 +128,6 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import org.bigbluebutton.modules.whiteboard.views.WhiteboardTextToolbar;
import org.bigbluebutton.modules.whiteboard.views.WhiteboardToolbar;
import org.bigbluebutton.util.i18n.ResourceUtil;
import org.bigbluebutton.main.api.JSLog;
private static const LOGGER:ILogger = getClassLogger(PresentationWindow);
@ -238,7 +238,9 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
}
private function newPresentationWindowHandler(): void {
presentationPodControls.selectedIndex = 0;
var event:RequestNewPresentationPodEvent = new RequestNewPresentationPodEvent(RequestNewPresentationPodEvent.REQUEST_NEW_PRES_POD);
event.requesterId = UsersUtil.getMyUserID();
localDispatcher.dispatchEvent(event);
}