From bb4caf1d5b862bd43706cff8975e220ce0a2500b Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Fri, 7 Dec 2012 19:20:55 +0000 Subject: [PATCH] - try adding some bw monitoring --- .../core/services/BandwidthMonitor.as | 137 ++++++++++++++++++ .../main/model/users/NetConnectionDelegate.as | 101 ++++++------- 2 files changed, 185 insertions(+), 53 deletions(-) create mode 100755 bigbluebutton-client/src/org/bigbluebutton/core/services/BandwidthMonitor.as diff --git a/bigbluebutton-client/src/org/bigbluebutton/core/services/BandwidthMonitor.as b/bigbluebutton-client/src/org/bigbluebutton/core/services/BandwidthMonitor.as new file mode 100755 index 0000000000..aaf5877e23 --- /dev/null +++ b/bigbluebutton-client/src/org/bigbluebutton/core/services/BandwidthMonitor.as @@ -0,0 +1,137 @@ +package org.bigbluebutton.core.services +{ + import flash.events.NetStatusEvent; + import flash.events.TimerEvent; + import flash.net.NetConnection; + import flash.utils.Timer; + + import org.red5.flash.bwcheck.ClientServerBandwidth; + import org.red5.flash.bwcheck.ServerClientBandwidth; + import org.red5.flash.bwcheck.events.BandwidthDetectEvent; + + public class BandwidthMonitor { + private var _serverURL:String = "localhost"; + private var _serverApplication:String = ""; + private var _clientServerService:String = ""; + private var _serverClientService:String = ""; + private var nc:NetConnection; + + private var bwTestTimer:Timer = new Timer(1000, 1); + + public function BandwidthMonitor() { + + } + + public function set serverURL(url:String):void { + _serverURL = url; + } + + public function set serverApplication(app:String):void { + _serverApplication = app; + } + + public function set clientServerService(service:String):void { + _clientServerService = "checkBandwidthUp"; + + } + + public function set serverClientService(service:String):void { + _serverClientService = "checkBandwidth"; + } + + public function start():void { + connect(); + } + + private function connect():void { + nc = new NetConnection(); + nc.objectEncoding = flash.net.ObjectEncoding.AMF0; + nc.client = this; + nc.addEventListener(NetStatusEvent.NET_STATUS, onStatus); + nc.connect("rtmpt://" + _serverURL + "/" + _serverApplication); + } + + + private function onStatus(event:NetStatusEvent):void + { + switch (event.info.code) + { + case "NetConnection.Connect.Success": + trace("\n" + event.info.code); +// trace("\n Detecting Server Client Bandwidth \n\n"); + monitor(); + break; + } + } + + private function monitor():void { + trace("Starting to monitor bandwidth"); + bwTestTimer = new Timer(30000); + bwTestTimer.addEventListener(TimerEvent.TIMER, rtmptRetryTimerHandler); + bwTestTimer.start(); + } + + private function rtmptRetryTimerHandler(event:TimerEvent):void { + trace("Starting to detect bandwidth from server to client."); + ServerClient(); + } + + public function ClientServer():void + { + var clientServer:ClientServerBandwidth = new ClientServerBandwidth(); + //connect(); + clientServer.connection = nc; + clientServer.service = _clientServerService; + clientServer.addEventListener(BandwidthDetectEvent.DETECT_COMPLETE,onClientServerComplete); + clientServer.addEventListener(BandwidthDetectEvent.DETECT_STATUS,onClientServerStatus); + clientServer.addEventListener(BandwidthDetectEvent.DETECT_FAILED,onDetectFailed); + clientServer.start(); + } + + public function ServerClient():void + { + var serverClient:ServerClientBandwidth = new ServerClientBandwidth(); + //connect(); + serverClient.connection = nc; + serverClient.service = _serverClientService; + serverClient.addEventListener(BandwidthDetectEvent.DETECT_COMPLETE,onServerClientComplete); + serverClient.addEventListener(BandwidthDetectEvent.DETECT_STATUS,onServerClientStatus); + serverClient.addEventListener(BandwidthDetectEvent.DETECT_FAILED,onDetectFailed); + trace("Monitoring client."); + serverClient.start(); + } + + public function onDetectFailed(event:BandwidthDetectEvent):void + { + trace("\n Detection failed with error: " + event.info.application + " " + event.info.description); + } + + public function onClientServerComplete(event:BandwidthDetectEvent):void + { + trace("\n\n kbitUp = " + event.info.kbitUp + ", deltaUp= " + event.info.deltaUp + ", deltaTime = " + event.info.deltaTime + ", latency = " + event.info.latency + " KBytes " + event.info.KBytes); + trace("\n\n Client to Server Bandwidth Detection Complete"); + } + + public function onClientServerStatus(event:BandwidthDetectEvent):void + { + if (event.info) { + trace("\n count: "+event.info.count+ " sent: "+event.info.sent+" timePassed: "+event.info.timePassed+" latency: "+event.info.latency+" overhead: "+event.info.overhead+" packet interval: " + event.info.pakInterval + " cumLatency: " + event.info.cumLatency); + } + } + + public function onServerClientComplete(event:BandwidthDetectEvent):void + { + trace("\n\n kbit Down: " + event.info.kbitDown + " Delta Down: " + event.info.deltaDown + " Delta Time: " + event.info.deltaTime + " Latency: " + event.info.latency); + trace("\n\n Server Client Bandwidth Detect Complete"); + trace("\n\n Detecting Client Server Bandwidth\n\n"); + ClientServer(); + } + + public function onServerClientStatus(event:BandwidthDetectEvent):void + { + if (event.info) { + trace("\n count: "+event.info.count+ " sent: "+event.info.sent+" timePassed: "+event.info.timePassed+" latency: "+event.info.latency+" cumLatency: " + event.info.cumLatency); + } + } + } +} \ No newline at end of file diff --git a/bigbluebutton-client/src/org/bigbluebutton/main/model/users/NetConnectionDelegate.as b/bigbluebutton-client/src/org/bigbluebutton/main/model/users/NetConnectionDelegate.as index 433e1d2a86..8c4e332227 100755 --- a/bigbluebutton-client/src/org/bigbluebutton/main/model/users/NetConnectionDelegate.as +++ b/bigbluebutton-client/src/org/bigbluebutton/main/model/users/NetConnectionDelegate.as @@ -18,16 +18,13 @@ */ package org.bigbluebutton.main.model.users { - import com.asfusion.mate.events.Dispatcher; - + import com.asfusion.mate.events.Dispatcher; import flash.events.*; import flash.net.NetConnection; import flash.net.Responder; import flash.utils.Timer; - - import mx.controls.Alert; - import org.bigbluebutton.common.LogUtil; + import org.bigbluebutton.core.services.BandwidthMonitor; import org.bigbluebutton.main.model.ConferenceParameters; import org.bigbluebutton.main.model.users.events.ConnectionFailedEvent; import org.bigbluebutton.main.model.users.events.UsersConnectionEvent; @@ -68,51 +65,45 @@ package org.bigbluebutton.main.model.users _netConnection.addEventListener( IOErrorEvent.IO_ERROR, netIOError ); } - public function setUri(uri:String):void { - _applicationURI = uri; - } + public function setUri(uri:String):void { + _applicationURI = uri; + } public function get connection():NetConnection { return _netConnection; } - public function addMessageListener(listener:IMessageListener):void - { - _messageListeners.push(listener); - } + public function addMessageListener(listener:IMessageListener):void { + _messageListeners.push(listener); + } - public function removeMessageListener(listener:IMessageListener):void - { - for (var ob:int=0; ob<_messageListeners.length; ob++) - { - if (_messageListeners[ob]==listener) - { - _messageListeners.splice (ob,1); - break; - } - } + public function removeMessageListener(listener:IMessageListener):void { + for (var ob:int=0; ob<_messageListeners.length; ob++) { + if (_messageListeners[ob] == listener) { + _messageListeners.splice (ob,1); + break; } + } + } - private function notifyListeners(messageName:String, message:Object):void - { - if (messageName != null && messageName != "") { - for (var notify:String in _messageListeners) - { - _messageListeners[notify].onMessage(messageName, message); - } - } else { - LogUtil.debug("Message name is undefined"); - } - } + private function notifyListeners(messageName:String, message:Object):void { + if (messageName != null && messageName != "") { + for (var notify:String in _messageListeners) { + _messageListeners[notify].onMessage(messageName, message); + } + } else { + LogUtil.debug("Message name is undefined"); + } + } - public function onMessageFromServer(messageName:String, result:Object):void { -// LogUtil.debug("Got message from server [" + messageName + "]"); - notifyListeners(messageName, result); - } + public function onMessageFromServer(messageName:String, result:Object):void { + trace("Got message from server [" + messageName + "]"); + notifyListeners(messageName, result); + } public function sendMessage(service:String, onSuccess:Function, onFailure:Function, message:Object=null):void { -// LogUtil.debug("SENDING [" + service + "]"); + trace("SENDING [" + service + "]"); var responder:Responder = new Responder( function(result:Object):void { // On successful result onSuccess("Successfully sent [" + service + "]."); @@ -130,7 +121,6 @@ package org.bigbluebutton.main.model.users } else { _netConnection.call(service, responder, message); } - } /** @@ -142,8 +132,7 @@ package org.bigbluebutton.main.model.users * mode: LIVE/PLAYBACK - Live:when used to collaborate, Playback:when being used to playback a recorded conference. * room: Need the room number when playing back a recorded conference. When LIVE, the room is taken from the URI. */ - public function connect(params:ConferenceParameters, tunnel:Boolean = false):void - { + public function connect(params:ConferenceParameters, tunnel:Boolean = false):void { _conferenceParameters = params; tried_tunneling = tunnel; @@ -157,10 +146,9 @@ package org.bigbluebutton.main.model.users _conferenceParameters.room, _conferenceParameters.voicebridge, _conferenceParameters.record, _conferenceParameters.externUserID, _conferenceParameters.internalUserID); - } catch( e : ArgumentError ) { + } catch(e:ArgumentError) { // Invalid parameters. - switch ( e.errorID ) - { + switch (e.errorID) { case 2004 : LogUtil.debug("Error! Invalid server location: " + uri); break; @@ -171,8 +159,7 @@ package org.bigbluebutton.main.model.users } } - public function disconnect(logoutOnUserCommand:Boolean) : void - { + public function disconnect(logoutOnUserCommand:Boolean):void { this.logoutOnUserCommand = logoutOnUserCommand; _netConnection.close(); } @@ -182,22 +169,31 @@ package org.bigbluebutton.main.model.users _netConnection.close(); } - protected function netStatus( event : NetStatusEvent ) : void - { + protected function netStatus(event:NetStatusEvent):void { handleResult( event ); } + private var _bwMon:BandwidthMonitor = new BandwidthMonitor(); + + private function startMonitoringBandwidth():void { + trace("Start monitoring bandwidth."); + _bwMon.serverURL = "192.168.0.249"; + _bwMon.serverApplication = "video"; + _bwMon.start(); + } + private var autoReconnectTimer:Timer = new Timer(1000, 1); - public function handleResult( event : Object ) : void { + public function handleResult(event:Object):void { var info : Object = event.info; var statusCode : String = info.code; - switch ( statusCode ) - { + switch (statusCode) { case "NetConnection.Connect.Success": LogUtil.debug(NAME + ":Connection to viewers application succeeded."); - + +// startMonitoringBandwidth(); + _netConnection.call( "getMyUserId",// Remote function name new Responder( @@ -270,7 +266,6 @@ package org.bigbluebutton.main.model.users private function autoReconnectTimerHandler(event:TimerEvent):void { LogUtil.debug(NAME + "autoReconnectTimerHandler: " + event); - Alert.show("Attempting to reconnect"); connect(_conferenceParameters, tried_tunneling); }