- break down DeskshareManager to make it simpler

This commit is contained in:
Richard Alam 2010-09-29 13:13:05 -04:00
parent 6836e5e8e6
commit 92ad5794cb
7 changed files with 299 additions and 109 deletions

View File

@ -25,25 +25,20 @@ package org.bigbluebutton.modules.deskshare.managers
import com.asfusion.mate.events.Dispatcher;
import org.bigbluebutton.common.IBbbModuleWindow;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.main.events.CloseWindowEvent;
import org.bigbluebutton.main.events.OpenWindowEvent;
import org.bigbluebutton.main.events.MadePresenterEvent;
import org.bigbluebutton.main.events.OpenWindowEvent;
import org.bigbluebutton.main.events.ToolbarButtonEvent;
import org.bigbluebutton.modules.deskshare.services.DeskshareService;
import org.bigbluebutton.modules.deskshare.view.components.DesktopPublishWindow;
import org.bigbluebutton.modules.deskshare.view.components.DesktopViewWindow;
import org.bigbluebutton.modules.deskshare.view.components.ToolbarButton;
import org.bigbluebutton.common.LogUtil;
public class DeskshareManager
{
private var shareWindow:DesktopPublishWindow;
private var viewWindow:DesktopViewWindow;
private var button:ToolbarButton;
private var publishWindowManager:PublishWindowManager;
private var viewWindowManager:ViewerWindowManager;
private var toolbarButtonManager:ToolbarButtonManager;
private var module:DeskShareModule;
private var service:DeskshareService;
private var isSharing:Boolean = false;
private var isViewing:Boolean = false;
private var globalDispatcher:Dispatcher;
private var buttonShownOnToolbar:Boolean = false;
@ -52,36 +47,26 @@ package org.bigbluebutton.modules.deskshare.managers
{
service = new DeskshareService();
globalDispatcher = new Dispatcher();
button = new ToolbarButton();
publishWindowManager = new PublishWindowManager(service);
viewWindowManager = new ViewerWindowManager(service);
toolbarButtonManager = new ToolbarButtonManager();
}
public function handleStartModuleEvent(module:DeskShareModule):void {
LogUtil.debug("Deskshare Module starting");
this.module = module;
service.connect(module.uri);
service.handleStartModuleEvent(module);
}
public function handleStopModuleEvent():void {
LogUtil.debug("Deskshare Module stopping");
stopSharing();
stopViewing();
notifyOthersToStopViewing();
publishWindowManager.stopSharing();
viewWindowManager.stopViewing();
service.disconnect();
}
private function stopSharing():void {
if (isSharing) shareWindow.stopSharing();
}
private function stopViewing():void {
if (isViewing) viewWindow.stopViewing();
}
public function handleStreamStartedEvent(videoWidth:Number, videoHeight:Number):void{
LogUtil.debug("Sending startViewing command");
isSharing = true;
button.enabled = false;
service.sendStartViewingNotification(videoWidth, videoHeight);
}
@ -99,41 +84,19 @@ package org.bigbluebutton.modules.deskshare.managers
*/
private function notifyOthersToStopViewing():void {
LogUtil.debug("notifyOthersToStopViewing()");
if (isSharing) {
button.enabled = true;
service.sendStopViewingNotification();
isSharing = false;
}
// if (isSharing) {
// button.enabled = true;
// service.sendStopViewingNotification();
// isSharing = false;
// }
}
private function addToolbarButton():void {
LogUtil.debug("DeskShare::addToolbarButton");
if ((button != null) && (!buttonShownOnToolbar)) {
button = new ToolbarButton();
var event:ToolbarButtonEvent = new ToolbarButtonEvent(ToolbarButtonEvent.ADD);
event.button = button;
globalDispatcher.dispatchEvent(event);
buttonShownOnToolbar = true;
}
}
private function removeToolbarButton():void {
if (buttonShownOnToolbar) {
var event:ToolbarButtonEvent = new ToolbarButtonEvent(ToolbarButtonEvent.REMOVE);
event.button = button;
globalDispatcher.dispatchEvent(event);
buttonShownOnToolbar = false;
}
}
/*
* Show the deskshare toolbar if this participant becomes the presenter.
*/
public function handleMadePresenterEvent(e:MadePresenterEvent):void{
LogUtil.debug("Got MadePresenterEvent ");
addToolbarButton();
toolbarButtonManager.addToolbarButton();
}
/*
@ -144,52 +107,27 @@ package org.bigbluebutton.modules.deskshare.managers
// stop sharing
// close window
// remove toolbar
removeToolbarButton();
toolbarButtonManager.removeToolbarButton();
}
public function handleStartSharingEvent():void {
LogUtil.debug("opening desk share window");
shareWindow = new DesktopPublishWindow();
shareWindow.initWindow(service.getConnection(), module.getCaptureServerUri(), module.getRoom());
shareWindow.visible = true;
openWindow(shareWindow);
LogUtil.debug("DeskshareManager::handleStartSharingEvent");
publishWindowManager.startSharing(module.getCaptureServerUri(), module.getRoom());
}
public function handleShareWindowCloseEvent():void {
button.enabled = true;
closeWindow(shareWindow);
toolbarButtonManager.enableToolbarButton();
publishWindowManager.handleShareWindowCloseEvent();
}
private function openWindow(window:IBbbModuleWindow):void{
var event:OpenWindowEvent = new OpenWindowEvent(OpenWindowEvent.OPEN_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
public function handleViewWindowCloseEvent():void {
LogUtil.debug("Received stop viewing command");
closeWindow(viewWindow);
isViewing = false;
LogUtil.debug("Received stop viewing command");
viewWindowManager.handleViewWindowCloseEvent();
}
private function closeWindow(window:IBbbModuleWindow):void {
var event:CloseWindowEvent = new CloseWindowEvent(CloseWindowEvent.CLOSE_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
public function handleStreamStartEvent(videoWidth:Number, videoHeight:Number):void{
LogUtil.debug("Received start vieweing command");
if (isSharing) {
LogUtil.debug("We are the one sharing, so ignore this message");
return;
}
LogUtil.debug("DeskShareEventsMap::startViewing");
viewWindow = new DesktopViewWindow();
viewWindow.startVideo(service.getConnection(), module.getRoom(), videoWidth, videoHeight);
openWindow(viewWindow);
isViewing = true;
viewWindowManager.handleStreamStartEvent(videoWidth, videoHeight);
}
}
}

View File

@ -0,0 +1,75 @@
/*
* BigBlueButton - http://www.bigbluebutton.org
*
* Copyright (c) 2008-2009 by respective authors (see below). All rights reserved.
*
* BigBlueButton is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Denis Zgonjanin <me.snap@gmail.com>
* Richard Alam <ritzalam@gmail.com>
* $Id: $
*/
package org.bigbluebutton.modules.deskshare.managers
{
import com.asfusion.mate.events.Dispatcher;
import org.bigbluebutton.common.IBbbModuleWindow;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.main.events.CloseWindowEvent;
import org.bigbluebutton.main.events.OpenWindowEvent;
import org.bigbluebutton.modules.deskshare.services.DeskshareService;
import org.bigbluebutton.modules.deskshare.view.components.DesktopPublishWindow;
public class PublishWindowManager {
private var shareWindow:DesktopPublishWindow;
private var isSharing:Boolean = false;
private var globalDispatcher:Dispatcher;
private var service:DeskshareService;
private var buttonShownOnToolbar:Boolean = false;
public function PublishWindowManager(service:DeskshareService) {
LogUtil.debug("PublishWindowManager init");
globalDispatcher = new Dispatcher();
this.service = service;
}
public function stopSharing():void {
if (isSharing) shareWindow.stopSharing();
}
public function startSharing(uri:String, room:String):void {
LogUtil.debug("DS:PublishWindowManager::opening desk share window");
shareWindow = new DesktopPublishWindow();
shareWindow.initWindow(service.getConnection(), uri, room);
shareWindow.visible = true;
openWindow(shareWindow);
}
public function handleShareWindowCloseEvent():void {
closeWindow(shareWindow);
}
private function openWindow(window:IBbbModuleWindow):void{
var event:OpenWindowEvent = new OpenWindowEvent(OpenWindowEvent.OPEN_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
private function closeWindow(window:IBbbModuleWindow):void {
var event:CloseWindowEvent = new CloseWindowEvent(CloseWindowEvent.CLOSE_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
}
}

View File

@ -0,0 +1,76 @@
/*
* BigBlueButton - http://www.bigbluebutton.org
*
* Copyright (c) 2008-2009 by respective authors (see below). All rights reserved.
*
* BigBlueButton is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Denis Zgonjanin <me.snap@gmail.com>
* Richard Alam <ritzalam@gmail.com>
* $Id: $
*/
package org.bigbluebutton.modules.deskshare.managers
{
import com.asfusion.mate.events.Dispatcher;
import org.bigbluebutton.common.IBbbModuleWindow;
import org.bigbluebutton.main.events.CloseWindowEvent;
import org.bigbluebutton.main.events.OpenWindowEvent;
import org.bigbluebutton.main.events.MadePresenterEvent;
import org.bigbluebutton.main.events.ToolbarButtonEvent;
import org.bigbluebutton.modules.deskshare.view.components.DesktopPublishWindow;
import org.bigbluebutton.modules.deskshare.view.components.DesktopViewWindow;
import org.bigbluebutton.modules.deskshare.view.components.ToolbarButton;
import org.bigbluebutton.common.LogUtil;
public class ToolbarButtonManager {
private var button:ToolbarButton;
private var isSharing:Boolean = false;
private var globalDispatcher:Dispatcher;
private var buttonShownOnToolbar:Boolean = false;
public function ToolbarButtonManager() {
globalDispatcher = new Dispatcher();
button = new ToolbarButton();
}
public function addToolbarButton():void {
LogUtil.debug("DeskShare::addToolbarButton");
if ((button != null) && (!buttonShownOnToolbar)) {
button = new ToolbarButton();
var event:ToolbarButtonEvent = new ToolbarButtonEvent(ToolbarButtonEvent.ADD);
event.button = button;
globalDispatcher.dispatchEvent(event);
buttonShownOnToolbar = true;
button.enabled = true;
}
}
public function removeToolbarButton():void {
if (buttonShownOnToolbar) {
var event:ToolbarButtonEvent = new ToolbarButtonEvent(ToolbarButtonEvent.REMOVE);
event.button = button;
globalDispatcher.dispatchEvent(event);
buttonShownOnToolbar = false;
}
}
public function enableToolbarButton():void {
button.enabled = true;
}
}
}

View File

@ -0,0 +1,91 @@
/*
* BigBlueButton - http://www.bigbluebutton.org
*
* Copyright (c) 2008-2009 by respective authors (see below). All rights reserved.
*
* BigBlueButton is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Denis Zgonjanin <me.snap@gmail.com>
* Richard Alam <ritzalam@gmail.com>
* $Id: $
*/
package org.bigbluebutton.modules.deskshare.managers
{
import com.asfusion.mate.events.Dispatcher;
import org.bigbluebutton.common.IBbbModuleWindow;
import org.bigbluebutton.main.events.CloseWindowEvent;
import org.bigbluebutton.main.events.OpenWindowEvent;
import org.bigbluebutton.main.events.MadePresenterEvent;
import org.bigbluebutton.main.events.ToolbarButtonEvent;
import org.bigbluebutton.modules.deskshare.services.DeskshareService;
import org.bigbluebutton.modules.deskshare.view.components.DesktopPublishWindow;
import org.bigbluebutton.modules.deskshare.view.components.DesktopViewWindow;
import org.bigbluebutton.modules.deskshare.view.components.ToolbarButton;
import org.bigbluebutton.common.LogUtil;
public class ViewerWindowManager {
private var viewWindow:DesktopViewWindow;
private var module:DeskShareModule;
private var service:DeskshareService;
private var isViewing:Boolean = false;
private var globalDispatcher:Dispatcher;
public function ViewerWindowManager(service:DeskshareService) {
this.service = service;
globalDispatcher = new Dispatcher();
}
public function handleStartModuleEvent(module:DeskShareModule):void {
LogUtil.debug("ViewerWindowManager starting");
this.module = module;
}
public function stopViewing():void {
if (isViewing) viewWindow.stopViewing();
}
public function handleStartedViewingEvent():void{
LogUtil.debug("ViewerWindowManager handleStartedViewingEvent");
service.sendStartedViewingNotification();
}
private function openWindow(window:IBbbModuleWindow):void{
var event:OpenWindowEvent = new OpenWindowEvent(OpenWindowEvent.OPEN_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
public function handleViewWindowCloseEvent():void {
LogUtil.debug("ViewerWindowManager Received stop viewing command");
closeWindow(viewWindow);
isViewing = false;
}
private function closeWindow(window:IBbbModuleWindow):void {
var event:CloseWindowEvent = new CloseWindowEvent(CloseWindowEvent.CLOSE_WINDOW_EVENT);
event.window = window;
globalDispatcher.dispatchEvent(event);
}
public function handleStreamStartEvent(videoWidth:Number, videoHeight:Number):void{
LogUtil.debug("ViewerWindowManager::startViewing");
viewWindow = new DesktopViewWindow();
viewWindow.startVideo(service.getConnection(), module.getRoom(), videoWidth, videoHeight);
openWindow(viewWindow);
isViewing = true;
}
}
}

View File

@ -27,8 +27,8 @@
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import org.bigbluebutton.modules.deskshare.managers.DeskshareManager;
import mx.events.FlexEvent;
import org.bigbluebutton.main.events.BBBEvent;
import org.bigbluebutton.main.events.MadePresenterEvent;
import org.bigbluebutton.modules.deskshare.events.ModuleEvent;
@ -38,14 +38,13 @@
import org.bigbluebutton.modules.deskshare.events.StreamEvent;
import org.bigbluebutton.modules.deskshare.events.ViewStreamEvent;
import org.bigbluebutton.modules.deskshare.events.ViewWindowEvent;
import org.bigbluebutton.modules.deskshare.managers.DeskshareManager;
]]>
</mx:Script>
<EventHandlers type="{FlexEvent.PREINITIALIZE}">
<!--
The FlexEvent.PREINITIALIZE event is a good place for creating and initializing managers.
-->
<ObjectBuilder generator="{DeskshareManager}"/>
<ObjectBuilder generator="{DeskshareManager}"/>
</EventHandlers>
<EventHandlers type="{ShareEvent.START_SHARING}">
@ -53,7 +52,7 @@
</EventHandlers>
<EventHandlers type="{BBBEvent.START_DESKSHARE}">
<MethodInvoker generator="{DeskshareManager}" method="handleStartSharingEvent"/>
<MethodInvoker generator="{DeskshareManager}" method="handleStartSharingEvent" />
</EventHandlers>
<EventHandlers type="{MadePresenterEvent.SWITCH_TO_PRESENTER_MODE}">
@ -63,11 +62,7 @@
<EventHandlers type="{MadePresenterEvent.SWITCH_TO_VIEWER_MODE}">
<MethodInvoker generator="{DeskshareManager}" method="handleMadeViewerEvent" arguments="{event}"/>
</EventHandlers>
<!--EventHandlers type="{MadePresenterEvent.BECOME_PRESENTER}">
<MethodInvoker generator="{DeskshareManager}" method="handleMadePresenterEvent" arguments="{event}"/>
</EventHandlers-->
<EventHandlers type="{StreamEvent.START}">
<MethodInvoker generator="{DeskshareManager}"
method="handleStreamStartedEvent" arguments="{[event.videoWidth, event.videoHeight]}"/>

View File

@ -27,12 +27,12 @@ package org.bigbluebutton.modules.deskshare.services
import flash.net.Responder;
import flash.net.SharedObject;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.common.red5.Connection;
import org.bigbluebutton.common.red5.ConnectionEvent;
import org.bigbluebutton.modules.deskshare.events.AppletStartedEvent;
import org.bigbluebutton.modules.deskshare.events.CursorEvent;
import org.bigbluebutton.modules.deskshare.events.ViewStreamEvent;
import org.bigbluebutton.common.LogUtil;
/**
* The DeskShareProxy communicates with the Red5 deskShare server application
@ -45,20 +45,24 @@ package org.bigbluebutton.modules.deskshare.services
private var nc:NetConnection;
private var deskSO:SharedObject;
private var responder:Responder;
private var module:DeskShareModule;
private var dispatcher:Dispatcher;
private var width:Number;
private var height:Number;
private var uri:String;
public function DeskshareService()
{
this.dispatcher = new Dispatcher();
}
public function handleStartModuleEvent(module:DeskShareModule):void {
LogUtil.debug("Deskshare Module starting");
this.module = module;
connect(module.uri);
}
public function connect(uri:String):void {
this.uri = uri;
LogUtil.debug("Deskshare Service connecting to " + uri);
conn = new Connection();
conn.addEventListener(Connection.SUCCESS, connectionSuccessHandler);
@ -91,9 +95,10 @@ package org.bigbluebutton.modules.deskshare.services
if (nc != null) nc.close();
}
private function connectionSuccessHandler(e:ConnectionEvent):void{
private function connectionSuccessHandler(e:ConnectionEvent):void{
LogUtil.debug("Successully connection to " + module.uri);
nc = conn.getConnection();
deskSO = SharedObject.getRemote("deskSO", uri, false);
deskSO = SharedObject.getRemote("deskSO", module.uri, false);
deskSO.client = this;
deskSO.connect(nc);
@ -105,11 +110,11 @@ package org.bigbluebutton.modules.deskshare.services
}
public function connectionFailedHandler(e:ConnectionEvent):void{
LogUtil.error("connection failed to " + uri + " with message " + e.toString());
LogUtil.error("connection failed to " + module.uri + " with message " + e.toString());
}
public function connectionRejectedHandler(e:ConnectionEvent):void{
LogUtil.error("connection rejected " + uri + " with message " + e.toString());
LogUtil.error("connection rejected " + module.uri + " with message " + e.toString());
}
/**

View File

@ -0,0 +1,10 @@
package org.bigbluebutton.modules.deskshare.services
{
public class SharedObjectCallbackHandler
{
public function SharedObjectCallbackHandler()
{
}
}
}