From 8ba3a216801dcdfd1f00326fe1bae50db50df785 Mon Sep 17 00:00:00 2001 From: perroned Date: Thu, 4 Feb 2016 11:39:20 -0800 Subject: [PATCH] WebRTC deskshare managers --- .../managers/WebRTCDeskshareManager.as | 185 ++++++++++++++++++ .../managers/WebRTCPublishWindowManager.as | 86 ++++++++ .../managers/WebRTCViewerWindowManager.as | 78 ++++++++ 3 files changed, 349 insertions(+) create mode 100755 bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCDeskshareManager.as create mode 100755 bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCPublishWindowManager.as create mode 100755 bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCViewerWindowManager.as diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCDeskshareManager.as b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCDeskshareManager.as new file mode 100755 index 0000000000..d2eda1092e --- /dev/null +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCDeskshareManager.as @@ -0,0 +1,185 @@ +/** +* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ +* +* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below). +* +* This program 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.0 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, see . +* +*/ + +package org.bigbluebutton.modules.deskshare.managers +{ + import com.asfusion.mate.events.Dispatcher; + + import flash.external.ExternalInterface; + + import org.as3commons.logging.api.ILogger; + import org.as3commons.logging.api.getClassLogger; + import org.bigbluebutton.core.UsersUtil; + import org.bigbluebutton.core.managers.UserManager; + import org.bigbluebutton.main.events.MadePresenterEvent; + import org.bigbluebutton.modules.deskshare.events.WebRTCViewStreamEvent; + import org.bigbluebutton.modules.deskshare.model.DeskshareOptions; + import org.bigbluebutton.modules.deskshare.services.WebRTCDeskshareService; + import org.bigbluebutton.modules.deskshare.utils.BrowserCheck; + + public class WebRTCDeskshareManager { + private static const LOGGER:ILogger = getClassLogger(WebRTCDeskshareManager); + + private var publishWindowManager:WebRTCPublishWindowManager; + private var viewWindowManager:WebRTCViewerWindowManager; + private var toolbarButtonManager:ToolbarButtonManager; + private var module:DeskShareModule; + private var service:WebRTCDeskshareService; + private var globalDispatcher:Dispatcher; + private var sharing:Boolean = false; + private var usingWebRTC:Boolean = false; + + public function WebRTCDeskshareManager() { + service = new WebRTCDeskshareService(); + globalDispatcher = new Dispatcher(); + publishWindowManager = new WebRTCPublishWindowManager(service); + viewWindowManager = new WebRTCViewerWindowManager(service); + toolbarButtonManager = new ToolbarButtonManager(); + } + + private function getChromeExtensionKey():String { + var key:String = 'your-extension-key'; + return key; + } + + private function getFreeswitchServerCredentials():Object { + var credentials:Object = new Object(); + credentials.vertoPort = "PORT"; + credentials.hostName = "HOST.NAME"; + credentials.login = "LOGIN"; + credentials.password = "PASSWORD"; + return credentials; + } + + public function handleStartModuleEvent(module:DeskShareModule):void { + LOGGER.debug("WebRTC Deskshare Module starting"); + this.module = module; + service.handleStartModuleEvent(module); + + if (UsersUtil.amIPresenter()) { + initDeskshare(); + } + } + + public function handleStopModuleEvent():void { + LOGGER.debug("WebRTC Deskshare Module stopping"); + + publishWindowManager.stopSharing(); + viewWindowManager.stopViewing(); + service.disconnect(); + } + + public function handleStreamStoppedEvent():void { + LOGGER.debug("DeskshareManager::handleStreamStoppedEvent Sending deskshare stopped command"); + stopWebRTCDeskshare(); + } + + private function stopWebRTCDeskshare():void { + LOGGER.debug("DeskshareManager::stopWebRTCDeskshare"); + if (ExternalInterface.available) { + var loggingCallback:Function = function():void {}; + var onSuccess:Function = function():void {}; + ExternalInterface.call("endScreenshare", loggingCallback, onSuccess); + } else { + LOGGER.error("Error! ExternalInterface not available (webrtcDeskshare)"); + } + } + + private function startWebRTCDeskshare():void { + LOGGER.debug("DeskshareManager::startWebRTCDeskshare"); + var result:String; + if (ExternalInterface.available) { + var loggingCallback:Function = function():void {}; + var videoTag:String = "localVertoVideo"; + var extensionId:String = getChromeExtensionKey(); + var modifyResolution:Boolean = false; + var onSuccess:Function = function():void { LOGGER.debug("onSuccess"); }; + var onFail:Function = function():void { LOGGER.debug("onSuccess"); }; + var vertoServerCredentials:Object = getFreeswitchServerCredentials(); + result = ExternalInterface.call("startScreenshare", loggingCallback, videoTag, vertoServerCredentials, extensionId, modifyResolution, onSuccess, onFail); + } + } + + private function initDeskshare():void { + sharing = false; + var options:DeskshareOptions = new DeskshareOptions(); + options.parseOptions(); + if (options.autoStart) { + handleStartSharingEvent(true); + } + if(options.showButton){ + toolbarButtonManager.addToolbarButton(); + } + } + + public function handleMadePresenterEvent(e:MadePresenterEvent):void { + LOGGER.debug("Got MadePresenterEvent "); + initDeskshare(); + } + + public function handleMadeViewerEvent(e:MadePresenterEvent):void{ + LOGGER.debug("Got MadeViewerEvent "); + toolbarButtonManager.removeToolbarButton(); + if (sharing) { + publishWindowManager.stopSharing(); + } + sharing = false; + } + + /*handle start sharing event*/ + public function handleStartSharingEvent(autoStart:Boolean):void { + LOGGER.debug("DeskshareManager::handleStartSharingEvent"); + var options:DeskshareOptions = new DeskshareOptions(); + options.parseOptions(); + + if (options.useWebRTCIfAvailable && BrowserCheck.isWebRTCSupported()) { + /*if (ChromeExtensionExists) {*/ + toolbarButtonManager.startedSharing(); + startWebRTCDeskshare(); + /*}*/ + } + } + + public function handleShareWindowCloseEvent():void { + //toolbarButtonManager.enableToolbarButton(); + publishWindowManager.handleShareWindowCloseEvent(); + sharing = false; + toolbarButtonManager.stopedSharing(); + } + + public function handleViewWindowCloseEvent():void { + LOGGER.debug("Received stop viewing command"); + viewWindowManager.handleViewWindowCloseEvent(); + } + + public function handleStreamStartEvent(e:WebRTCViewStreamEvent):void{ + // if (sharing) return; //TODO must uncomment this for the non-webrtc desktop share + var isPresenter:Boolean = UserManager.getInstance().getConference().amIPresenter; + LOGGER.debug("Received start vieweing command when isPresenter==[{0}]",[isPresenter]); + + if(isPresenter) { + publishWindowManager.startViewing(e.rtmp, e.videoWidth, e.videoHeight); + } else { + viewWindowManager.startViewing(e.rtmp, e.videoWidth, e.videoHeight); + } + + // sharing = true; //TODO must uncomment this for the non-webrtc desktop share + } + } +} diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCPublishWindowManager.as b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCPublishWindowManager.as new file mode 100755 index 0000000000..6385bcb941 --- /dev/null +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCPublishWindowManager.as @@ -0,0 +1,86 @@ +/** +* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ +* +* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below). +* +* This program 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.0 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, see . +* +*/ + +package org.bigbluebutton.modules.deskshare.managers +{ + import com.asfusion.mate.events.Dispatcher; + + import flash.events.TimerEvent; + import flash.utils.Timer; + + import org.as3commons.logging.api.ILogger; + import org.as3commons.logging.api.getClassLogger; + import org.bigbluebutton.common.IBbbModuleWindow; + import org.bigbluebutton.common.events.CloseWindowEvent; + import org.bigbluebutton.common.events.OpenWindowEvent; + import org.bigbluebutton.modules.deskshare.services.WebRTCDeskshareService; + import org.bigbluebutton.modules.deskshare.view.components.WebRTCDesktopPublishWindow; + + public class WebRTCPublishWindowManager { + private static const LOGGER:ILogger = getClassLogger(PublishWindowManager); + + private var shareWindow:WebRTCDesktopPublishWindow; + private var globalDispatcher:Dispatcher; + private var service:WebRTCDeskshareService; + private var buttonShownOnToolbar:Boolean = false; + + // Timer to auto-publish webcam. We need this timer to delay + // the auto-publishing until after the Viewers's window has loaded + // to receive the publishing events. Otherwise, the user joining next + // won't be able to view the webcam. + private var autoPublishTimer:Timer; + + public function WebRTCPublishWindowManager(service:WebRTCDeskshareService) { + LOGGER.debug("PublishWindowManager init"); + globalDispatcher = new Dispatcher(); + this.service = service; + } + + public function stopSharing():void { + if (shareWindow != null) shareWindow.stopSharing(); + } + + private function autopublishTimerHandler(event:TimerEvent):void { + shareWindow.shareScreen(true); + } + + 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); + } + + public function startViewing(rtmp:String, videoWidth:Number, videoHeight:Number):void{ + shareWindow = new WebRTCDesktopPublishWindow(); + shareWindow.visible = true; + openWindow(shareWindow); + shareWindow.startVideo(rtmp, videoWidth, videoHeight); + } + } +} diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCViewerWindowManager.as b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCViewerWindowManager.as new file mode 100755 index 0000000000..90233a0c82 --- /dev/null +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/deskshare/managers/WebRTCViewerWindowManager.as @@ -0,0 +1,78 @@ +/** +* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ +* +* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below). +* +* This program 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.0 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, see . +* +*/ + +package org.bigbluebutton.modules.deskshare.managers +{ + import com.asfusion.mate.events.Dispatcher; + + import org.as3commons.logging.api.ILogger; + import org.as3commons.logging.api.getClassLogger; + import org.bigbluebutton.common.IBbbModuleWindow; + import org.bigbluebutton.common.events.CloseWindowEvent; + import org.bigbluebutton.common.events.OpenWindowEvent; + import org.bigbluebutton.modules.deskshare.services.WebRTCDeskshareService; + import org.bigbluebutton.modules.deskshare.view.components.WebRTCDesktopPublishWindow; + import org.bigbluebutton.modules.deskshare.view.components.WebRTCDesktopViewWindow; + + public class WebRTCViewerWindowManager { + private static const LOGGER:ILogger = getClassLogger(ViewerWindowManager); + + private var viewWindow:WebRTCDesktopViewWindow; + private var shareWindow:WebRTCDesktopPublishWindow; + private var service:WebRTCDeskshareService; + private var isViewing:Boolean = false; + private var globalDispatcher:Dispatcher; + + public function WebRTCViewerWindowManager(service:WebRTCDeskshareService) { + this.service = service; + globalDispatcher = new Dispatcher(); + } + + public function stopViewing():void { + if (isViewing) viewWindow.stopViewing(); + } + + 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 { + LOGGER.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 startViewing(rtmp:String, videoWidth:Number, videoHeight:Number):void{ + LOGGER.debug("ViewerWindowManager::startViewing"); + + viewWindow = new WebRTCDesktopViewWindow(); + viewWindow.startVideo(rtmp, videoWidth, videoHeight); + openWindow(viewWindow); + isViewing = true; + } + } +}