Add multiple netstream for each webcam

This commit is contained in:
Hugo Lazzari 2013-06-24 10:21:22 -03:00
parent c7c6703d67
commit 952d235460
3 changed files with 105 additions and 44 deletions

View File

@ -49,6 +49,8 @@ package org.bigbluebutton.modules.videoconf.business
private var nc:NetConnection;
private var ns:NetStream;
private var _url:String;
private var camerasPublishing:Object = new Object();
private var connected:Boolean = false;
private function parseOptions():void {
videoOptions = new VideoConfOptions();
@ -86,11 +88,13 @@ package org.bigbluebutton.modules.videoconf.business
private function onNetStatus(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
ns = new NetStream(nc);
connected = true;
//ns = new NetStream(nc);
onConnectedToVideoApp();
break;
default:
LogUtil.debug("[" + event.info.code + "] for [" + _url + "]");
connected = false;
break;
}
}
@ -103,6 +107,7 @@ package org.bigbluebutton.modules.videoconf.business
}
public function startPublishing(e:StartBroadcastEvent):void{
var ns:NetStream = new NetStream(nc);
ns.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
ns.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
ns.addEventListener( AsyncErrorEvent.ASYNC_ERROR, onAsyncError );
@ -160,22 +165,33 @@ package org.bigbluebutton.modules.videoconf.business
}
ns.publish(e.stream);
camerasPublishing[e.stream] = ns;
}
public function stopBroadcasting():void{
public function stopBroadcasting(stream:String):void{
trace("Closing netstream for webcam publishing");
if (ns != null) {
if (camerasPublishing[stream] != null) {
var ns:NetStream = camerasPublishing[stream];
ns.attachCamera(null);
ns.close();
ns = null;
ns = new NetStream(nc);
}
delete camerasPublishing[stream];
}
}
public function stopAllBroadcasting():void {
for each (var ns:NetStream in camerasPublishing)
{
ns.attachCamera(null);
ns.close();
ns = null;
}
camerasPublishing = new Object();
}
public function disconnect():void {
trace("VideoProxy:: disconnecting from Video application");
stopBroadcasting();
stopAllBroadcasting();
if (nc != null) nc.close();
}

View File

@ -54,6 +54,7 @@ package org.bigbluebutton.modules.videoconf.maps
import org.bigbluebutton.modules.videoconf.views.ToolbarPopupButton;
import org.bigbluebutton.modules.videoconf.views.VideoWindow;
import org.flexunit.runner.manipulation.filters.IncludeAllFilter;
import mx.collections.ArrayList;
public class VideoEventMapDelegate
{
@ -71,6 +72,8 @@ package org.bigbluebutton.modules.videoconf.maps
private var _isPublishing:Boolean = false;
private var _isPreviewWebcamOpen:Boolean = false;
private var _isWaitingActivation:Boolean = false;
private var streamList:ArrayList = new ArrayList();
private var numberOfWindows:Object = new Object();
public function VideoEventMapDelegate(dispatcher:IEventDispatcher)
{
@ -187,17 +190,28 @@ package org.bigbluebutton.modules.videoconf.maps
private function openPublishWindowFor(userID:String, camIndex:int, camWidth:int, camHeight:int):void {
var publishWindow:PublishWindow = new PublishWindow();
publishWindow.userID = userID;
if(numberOfWindows[userID] == null)
numberOfWindows[userID] = 0;
publishWindow.userID = userID + "-" + String(numberOfWindows[userID]);
numberOfWindows[userID] = numberOfWindows[userID] + 1;
publishWindow.title = UsersUtil.getUserName(userID);
publishWindow.camIndex = camIndex;
publishWindow.setResolution(camWidth, camHeight);
publishWindow.videoOptions = options;
publishWindow.quality = options.videoQuality;
publishWindow.resolutions = options.resolutions.split(",");
for(var i:int = 0; i < numberOfWindows[userID] - 1; i++) {
if(PublishWindow(webcamWindows.getWindow(userID + "-" + String(i))).camIndex == camIndex) {
closeWindow(userID + "-" + String(i));
numberOfWindows[userID] = numberOfWindows[userID] - 1;
publishWindow.userID = userID + "-" + String(i);
break;
}
}
trace("VideoEventMapDelegate:: [" + me + "] openPublishWindowFor:: Closing window for [" + userID + "] [" + UsersUtil.getUserName(userID) + "]");
closeWindow(userID);
//closeWindow(userID);
webcamWindows.addWindow(publishWindow);
@ -227,14 +241,18 @@ package org.bigbluebutton.modules.videoconf.maps
private function openViewWindowFor(userID:String):void {
trace("VideoEventMapDelegate:: [" + me + "] openViewWindowFor:: Opening VIEW window for [" + userID + "] [" + UsersUtil.getUserName(userID) + "]");
if(numberOfWindows[userID] != null) {
for(var i:int = 0; i < numberOfWindows[userID]; i++) {
closeWindow(userID + "-" + String(i));
}
}
var window:VideoWindow = new VideoWindow();
window.userID = userID;
window.videoOptions = options;
window.resolutions = options.resolutions.split(",");
window.title = UsersUtil.getUserName(userID);
var window:VideoWindow = new VideoWindow();
window.userID = userID;
window.videoOptions = options;
window.resolutions = options.resolutions.split(",");
window.title = UsersUtil.getUserName(userID);
closeWindow(userID);
var bbbUser:BBBUser = UsersUtil.getUser(userID);
window.startVideo(proxy.connection, bbbUser.streamName);
@ -263,8 +281,10 @@ package org.bigbluebutton.modules.videoconf.maps
}
public function startPublishing(e:StartBroadcastEvent):void{
LogUtil.debug("VideoEventMapDelegate:: [" + me + "] startPublishing:: Publishing stream to: " + proxy.connection.uri + "/" + e.stream);
streamName = e.stream;
LogUtil.debug("ESTOU AQUI");
proxy.startPublishing(e);
_isWaitingActivation = false;
@ -272,7 +292,16 @@ package org.bigbluebutton.modules.videoconf.maps
UsersUtil.setIAmPublishing(true);
var broadcastEvent:BroadcastStartedEvent = new BroadcastStartedEvent();
broadcastEvent.stream = e.stream;
//broadcastEvent.stream = e.stream;
if(streamList.length == 0) {
streamList.addItem(e.stream);
broadcastEvent.stream = e.stream;
}
else {
streamList.addItem(e.stream);
var myPattern:RegExp = /,/g;
broadcastEvent.stream = streamList.toString().replace(myPattern, "|");
}
broadcastEvent.userid = UsersUtil.getMyUserID();
broadcastEvent.isPresenter = UsersUtil.amIPresenter();
broadcastEvent.camSettings = UsersUtil.amIPublishing();
@ -285,13 +314,28 @@ package org.bigbluebutton.modules.videoconf.maps
public function stopPublishing(e:StopBroadcastEvent):void{
trace("VideoEventMapDelegate:: [" + me + "] Stop publishing. ready = [" + _ready + "]");
stopBroadcasting();
stopBroadcasting(e.stream);
if(streamList.length <= 1) {
streamList.removeItem(e.stream);
var broadcastEvent:BroadcastStoppedEvent = new BroadcastStoppedEvent();
broadcastEvent.stream = e.stream;
broadcastEvent.userid = UsersUtil.getMyUserID();
_dispatcher.dispatchEvent(broadcastEvent);
}
else {
streamList.removeItem(e.stream);
var broadcastStartEvent:BroadcastStartedEvent = new BroadcastStartedEvent();
var myPattern:RegExp = /,/g;
broadcastStartEvent.stream = streamList.toString().replace(myPattern, "|");
broadcastStartEvent.userid = UsersUtil.getMyUserID();
_dispatcher.dispatchEvent(broadcastStartEvent);
}
}
private function stopBroadcasting():void {
private function stopBroadcasting(stream:String):void {
trace("Stopping broadcast of webcam");
proxy.stopBroadcasting();
proxy.stopBroadcasting(stream);
_isPublishing = false;
UsersUtil.setIAmPublishing(false);
@ -317,14 +361,15 @@ package org.bigbluebutton.modules.videoconf.maps
}
public function handleClosePublishWindowEvent(event:ClosePublishWindowEvent):void {
if (_isPublishing) {
stopBroadcasting();
}
//if (_isPublishing) {
// stopBroadcasting();
//}
}
public function handleShareCameraRequestEvent(event:ShareCameraRequestEvent):void {
LogUtil.debug("Webcam: "+_isPublishing + " " + _isPreviewWebcamOpen);
if (!_isPublishing && !_isPreviewWebcamOpen && !_isWaitingActivation)
//if (!_isPublishing && !_isPreviewWebcamOpen && !_isWaitingActivation)
if (!_isPreviewWebcamOpen && !_isWaitingActivation)
openWebcamPreview(event.publishInClient, event.defaultCamera, event.camerasArray);
}
@ -352,9 +397,9 @@ package org.bigbluebutton.modules.videoconf.maps
public function closeAllWindows():void{
trace("VideoEventMapDelegate:: closing all windows");
if (_isPublishing) {
stopBroadcasting();
}
//if (_isPublishing) {
// stopBroadcasting();
//}
_dispatcher.dispatchEvent(new CloseAllWindowsEvent());
}
@ -376,9 +421,9 @@ package org.bigbluebutton.modules.videoconf.maps
if (options.presenterShareOnly){
button.isPresenter = false;
if (_isPublishing) {
stopBroadcasting();
}
//if (_isPublishing) {
// stopBroadcasting();
//}
}
}

View File

@ -22,13 +22,13 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<pubVid:VideoWindowItf
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:pubVid="org.bigbluebutton.modules.videoconf.business.*"
initialize="init()"
xmlns:pubVid="org.bigbluebutton.modules.videoconf.business.*"
initialize="init()"
implements="org.bigbluebutton.common.IBbbModuleWindow"
styleNameFocus="videoPublishStyleFocus"
styleNameNoFocus="videoPublishStyleNoFocus"
creationComplete="onCreationComplete()"
width="{defaultWidth + 6}" height="{defaultHeight + 6}"
width="{defaultWidth + 6}" height="{defaultHeight + 6}"
xmlns:mate="http://mate.asfusion.com/"
resize="onResize()"
horizontalScrollPolicy="off"
@ -102,12 +102,12 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
[Bindable] public var glowColor:String = "";
[Bindable] public var glowBlurSize:Number = 0;
private function init():void{
videoOptions = new VideoConfOptions();
baseIndex = videoOptions.baseTabIndex;
}
private var windowType:String = "PublishWindowType";
override public function getWindowType():String {
@ -140,19 +140,19 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
autoPublishTimer.start();
}
titleBarOverlay.tabIndex = baseIndex;
titleBarOverlay.accessibilityName = ResourceUtil.getInstance().getString('bbb.video.publish.titleBar');
closeBtn.focusEnabled = true;
closeBtn.tabIndex = baseIndex+3;
closeBtn.tabIndex = baseIndex+3;
addEventListener(MDIWindowEvent.RESIZE_START, onResizeStart);
addEventListener(MDIWindowEvent.RESIZE_END, onResizeEnd);
addEventListener(MouseEvent.MOUSE_OVER, showButtons);
addEventListener(MouseEvent.MOUSE_OUT, hideButtons);
addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
// start the camera preview
// start the camera preview
updateCamera();
}
@ -160,7 +160,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
focusManager.setFocus(closeBtn);
}
private function autopublishTimerHandler(event:TimerEvent):void {
private function autopublishTimerHandler(event:TimerEvent):void {
startPublishing();
autoPublishTimer.stop();
}
@ -464,10 +464,10 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
blurXFrom="{glowBlurSize}" blurXTo="0.0" blurYFrom="{glowBlurSize}" blurYTo="0.0" color="{glowColor}"/>
<mx:Fade id="dissolveOut" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:Fade id="dissolveIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>
<mx:Fade id="dissolveIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>
<mx:Text id="lblWarning" width="100%" textAlign="right" fontSize="14" fontWeight="bold" y="{this.height - lblWarning.height - 30}"
visible="false" selectable="false" hideEffect="{dissolveOut}" showEffect="{dissolveIn}"/>
<mate:Listener type="{CloseAllWindowsEvent.CLOSE_ALL_WINDOWS}" method="closeWindow" />
<mate:Listener type="{CloseAllWindowsEvent.CLOSE_ALL_WINDOWS}" method="closeWindow" />
</pubVid:VideoWindowItf>