Merge pull request #3430 from ritzalam/random-port-test-ids

close port test connection right after test.
This commit is contained in:
Richard Alam 2016-10-26 13:10:04 -04:00 committed by GitHub
commit 9e86e95275
2 changed files with 7 additions and 33 deletions

View File

@ -1,3 +1,3 @@
/** * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ * * Copyright (c) 2012 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.main.model { import flash.events.NetStatusEvent; import flash.events.TimerEvent; import flash.net.NetConnection; import flash.net.ObjectEncoding; import flash.utils.Timer; import org.as3commons.logging.api.ILogger; import org.as3commons.logging.api.getClassLogger; [Bindable] /** * Test RTMP port. * * @author Thijs Triemstra ( info@collab.nl ) */ public class PortTest { private static const LOGGER:ILogger = getClassLogger(PortTest); /** * Connect using rtmp or rtmpt. */ private var tunnel: Boolean; /** * RTMP hostname. */ private var hostname : String; /** * RTMP port. */ public var port : String; /** * RTMP port. */ public var portName : String = "Default"; /** * RTMP application. */ private var application : String; /** * Base RTMP URI. */ private var baseURI : String; /** * RTMP connection. */ public var nc : NetConnection; /** * Connection status. */ public var status : String; private var _connectionListener:Function; /** * Timer to control timeout of connection test */ private var testTimeout:Number = 0; /** * Timer to control timeout of connection test */ private var connectionTimer:Timer; /** * Set default encoding to AMF0 so FMS also understands. */ NetConnection.defaultObjectEncoding = ObjectEncoding.AMF0; /** * Create new port test and connect to the RTMP server. * * @param protocol * @param hostname * @param port * @param application * @testTimeout timeout of test in milliseconds */ public function PortTest( tunnel : Boolean, hostname : String = "", port : String = "", application : String = "", testTimeout : Number = 10000) { this.tunnel = tunnel; this.hostname = hostname; this.application = application; this.testTimeout = testTimeout; if ( port.length > 0 ) { this.portName = port; this.port = ":" + port; } else { this.port = port; } // Construct URI. if (tunnel) { this.baseURI = "rtmpt://" + this.hostname + "/" + this.application; } else { this.baseURI = "rtmp://" + this.hostname + this.port + "/" + this.application; } * @author Thijs Triemstra ( info@collab.nl ) // * /** * Start connection. */ public function connect() : void { this.nc = new NetConnection(); this.nc.client = this;
this.nc.proxyType = "best";
this.nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); // connect to server try { LOGGER.debug("Testing connection to " + this.baseURI); // Create connection with the server. this.nc.connect( this.baseURI, "portTestMeetingId", "portTestDummyUserId" ); status = "Connecting..."; this.nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); connectionTimer = new Timer(testTimeout, 1); this.nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); // connect to server connectionTimer.start(); } catch( e : ArgumentError ) { // Invalid parameters. status = "ERROR: " + e.message; } } /** * Method called when connection timed out */ // connect to server { { LOGGER.debug("Timedout trying to connect to " + this.baseURI); status = "FAILED"; _connectionListener(status, tunnel, hostname, port, application); close(); } /** * Close connection. */ public function close() : void { try { try LOGGER.debug("Testing connection to " + this.baseURI); try try // Create connection with the server. try this.nc.connect( this.baseURI, "portTestMeetingId", "portTestDummyUserId" ); // Close the NetConnection. { } /** * Catch NetStatusEvents. * * @param event */ { { // connect to server LOGGER.debug("Testing connection to " + this.baseURI); var info : Object = event.info; var statusCode : String = info.code; { this.nc.connect( this.baseURI, "portTestMeetingId", "portTestDummyUserId" ); // Close NetConnection. LOGGER.debug("Testing connection to " + this.baseURI); { // Create connection with the server. if ( statusCode == "NetConnection.Connect.Success" ) { status = "SUCCESS"; LOGGER.debug("Successfully connected to " + this.baseURI); _connectionListener(status, tunnel, hostname, port, application); } else if ( statusCode == "NetConnection.Connect.Rejected" || statusCode == "NetConnection.Connect.Failed" || statusCode == "NetConnection.Connect.Closed" ) { LOGGER.debug("Failed to connect to " + this.baseURI); status = "FAILED"; _connectionListener(status, tunnel, hostname, port, application); } } public function onBWCheck(... rest):Number { return 0; } public function onBWDone(... rest):void { var p_bw:Number; if (rest.length > 0) p_bw = rest[0]; // your application should do something here // when the bandwidth check is complete LOGGER.debug("bandwidth = {0} Kbps.", [p_bw]); } public function addConnectionSuccessListener(listener:Function):void { _connectionListener = listener; } } }
/** * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ * * Copyright (c) 2012 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.main.model { import flash.events.NetStatusEvent; import flash.events.TimerEvent; import flash.net.NetConnection; import flash.net.ObjectEncoding; import flash.utils.Timer; import flash.utils.Dictionary; import org.as3commons.logging.api.ILogger; import org.as3commons.logging.api.getClassLogger; [Bindable] /** * Test RTMP port. * * @author Thijs Triemstra ( info@collab.nl ) */ public class PortTest { private static const LOGGER:ILogger = getClassLogger(PortTest); /** * Connect using rtmp or rtmpt. */ private var tunnel: Boolean; /** * RTMP hostname. */ private var hostname : String; /** * RTMP port. */ public var port : String; /** * RTMP port. */ public var portName : String = "Default"; /** * RTMP application. */ private var application : String; /** * Base RTMP URI. */ private var baseURI : String; /** * RTMP connection. */ public var nc : NetConnection; /** * Connection status. */ public var status : String; private var _connectionListener:Function; /** * Timer to control timeout of connection test */ private var testTimeout:Number = 0; /** * Timer to control timeout of connection test */ private var connectionTimer:Timer; private var closeConnectionTimer:Timer; /** * Set default encoding to AMF0 so FMS also understands. */ NetConnection.defaultObjectEncoding = ObjectEncoding.AMF0; /** * Create new port test and connect to the RTMP server. * * @param protocol * @param hostname * @param port * @param application * @testTimeout timeout of test in milliseconds */ public function PortTest( tunnel : Boolean, hostname : String = "", port : String = "", application : String = "", testTimeout : Number = 10000) { this.tunnel = tunnel; this.hostname = hostname; this.application = application; this.testTimeout = testTimeout; if ( port.length > 0 ) { this.portName = port; this.port = ":" + port; } else { this.port = port; } // Construct URI. if (tunnel) { this.baseURI = "rtmpt://" + this.hostname + "/" + this.application; } else { this.baseURI = "rtmp://" + this.hostname + this.port + "/" + this.application; } * @author Thijs Triemstra ( info@collab.nl ) /** * Start connection. */ public function connect():void { nc = new NetConnection(); nc.client = this;
nc.proxyType = "best";
nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); // connect to server try { LOGGER.debug("Testing connection to " + this.baseURI); connectionTimer = new Timer(testTimeout, 1); // Create connection with the server. this.nc.connect( this.baseURI, "portTestMeetingId", "portTestDummyUserId" ); status = "Connecting..."; // Create connection with the server. // Create connection with the server. status = "Connecting..."; // Create connection with the server. this.nc.addEventListener( NetStatusEvent.NET_STATUS, netStatus ); // Invalid parameters. status = "ERROR: " + e.message; } } /** * Method called when connection timed out */ // Create connection with the server. // connect to server LOGGER.debug("Timedout trying to connect to " + this.baseURI); status = "FAILED"; _connectionListener(status, tunnel, hostname, port, application); closeConnection(); } /** * Close connection. */ // Create connection with the server. { // Create connection with the server. LOGGER.debug("Testing connection to " + this.baseURI); // Create connection with the server. // Create connection with the server. // Create connection with the server. // Create connection with the server. this.nc.connect( this.baseURI, "portTestMeetingId", "portTestDummyUserId" ); nc.removeEventListener( NetStatusEvent.NET_STATUS, netStatus ); // Close the NetConnection. nc.close(); } private function closeConnection():void { closeConnectionTimer = new Timer(100, 1); closeConnectionTimer.addEventListener(TimerEvent.TIMER, closeConnectionTimerHandler); closeConnectionTimer.start(); } private function closeConnectionTimerHandler (e:TimerEvent) : void { LOGGER.debug("Closing connection to " + this.baseURI); close(); } /** * Catch NetStatusEvents. * * @param event */ protected function netStatus(event : NetStatusEvent):void { { // Create connection with the server. //Stop timeout timer when connected/rejected status = "Connecting..."; // connect to server { LOGGER.debug("Testing connection to " + this.baseURI); { if ( statusCode == "NetConnection.Connect.Success" ) { status = "SUCCESS"; LOGGER.debug("Successfully connected to " + this.baseURI); _connectionListener(status, tunnel, hostname, port, application); } else if ( statusCode == "NetConnection.Connect.Rejected" || statusCode == "NetConnection.Connect.Failed" || statusCode == "NetConnection.Connect.Closed" ) { LOGGER.debug("Failed to connect to " + this.baseURI); status = "FAILED"; _connectionListener(status, tunnel, hostname, port, application); } closeConnection(); } public function onBWCheck(... rest):Number { return 0; } public function onBWDone(... rest):void { var p_bw:Number; if (rest.length > 0) p_bw = rest[0]; // your application should do something here // when the bandwidth check is complete LOGGER.debug("bandwidth = {0} Kbps.", [p_bw]); } public function addConnectionSuccessListener(listener:Function):void { _connectionListener = listener; } } }

View File

@ -27,12 +27,12 @@ package org.bigbluebutton.main.model {
public class PortTestProxy {
private static const LOGGER:ILogger = getClassLogger(PortTestProxy);
private var nc:NetConnection;
private var tunnel:Boolean;
private var port:String;
private var hostname:String;
private var application:String;
private var modulesDispatcher:ModulesDispatcher;
private var portTest:PortTest;
public function PortTestProxy(modulesDispatcher: ModulesDispatcher) {
this.modulesDispatcher = modulesDispatcher;
@ -40,45 +40,19 @@ package org.bigbluebutton.main.model {
public function connect(tunnel:Boolean, hostname:String = "", port:String = "", application:String = "", testTimeout:Number = 10000):void {
this.tunnel = tunnel;
var portTest:PortTest = new PortTest(tunnel, hostname, port, application, testTimeout);
portTest = new PortTest(tunnel, hostname, port, application, testTimeout);
portTest.addConnectionSuccessListener(connectionListener);
portTest.connect();
}
private function connectionListener(status:String, tunnel:Boolean, hostname:String, port:String, application:String):void {
if (status == "SUCCESS") {
modulesDispatcher.sendPortTestSuccessEvent(port, hostname, tunnel, application);
} else {
modulesDispatcher.sendPortTestFailedEvent(port, hostname, tunnel, application);
}
}
public function close():void {
nc.removeEventListener(NetStatusEvent.NET_STATUS, netStatusEventHandler);
nc.close();
}
protected function netStatusEventHandler(event:NetStatusEvent):void {
var info:Object = event.info;
var statusCode : String = info.code;
if (statusCode == "NetConnection.Connect.Success") {
modulesDispatcher.sendPortTestSuccessEvent(port, hostname, tunnel, application);
} else if (statusCode == "NetConnection.Connect.Rejected" ||
statusCode == "NetConnection.Connect.Failed" ||
statusCode == "NetConnection.Connect.Closed" ) {
modulesDispatcher.sendPortTestFailedEvent(port, hostname, tunnel, application);
} else {
modulesDispatcher.sendPortTestFailedEvent(port, hostname, tunnel, application);
}
// Close NetConnection.
close();
}
/**
* The Red5 oflaDemo returns bandwidth stats.
*/
public function onBWDone() : void { }
}
}