WebRTC deskshare managers

This commit is contained in:
perroned 2016-02-04 11:39:20 -08:00
parent 9f2cfa8f35
commit 8ba3a21680
3 changed files with 349 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}
}