From 2f30fd44856243b5b5a017ef4a9892c5cdb1ca5e Mon Sep 17 00:00:00 2001 From: Richard Alam <ritzalam@gmail.com> Date: Wed, 17 Apr 2013 21:47:12 +0000 Subject: [PATCH] - check if user can connect using RTMP or RTMPT --- bigbluebutton-client/build.xml | 11 +- .../resources/prod/check/bbb-check.html | 25 +++ .../resources/prod/check/lib/bbb_check.js | 52 ++++++ .../prod/check/lib/pre_flight_check.js | 8 + bigbluebutton-client/src/RTMPConnCheck.mxml | 159 ++++++++++++++++++ 5 files changed, 253 insertions(+), 2 deletions(-) create mode 100755 bigbluebutton-client/src/RTMPConnCheck.mxml diff --git a/bigbluebutton-client/build.xml b/bigbluebutton-client/build.xml index 4e8c71758b..f452854e16 100755 --- a/bigbluebutton-client/build.xml +++ b/bigbluebutton-client/build.xml @@ -30,6 +30,7 @@ <property name="CAM_PREVIEW_SA" value="WebcamPreviewStandalone" /> <property name="MICROPHONE_CHECK" value="MicrophoneCheck" /> <property name="CAMERA_CHECK" value="CameraCheck" /> + <property name="CONNECTION_CHECK" value="RTMPConnCheck" /> <property name="CAM_VIEW_SA" value="WebcamViewStandalone" /> <property name="PHONE" value="PhoneModule" /> <property name="NOTES" value="NotesModule" /> @@ -239,7 +240,12 @@ <echo message="Compiling Camera Check Application." /> <build-module-no-link src="${SRC_DIR}" target="${CAMERA_CHECK}" /> </target> - + + <target name="build-conn-check" description="Compile Connection Check Application"> + <echo message="Compiling Connection Check Application." /> + <build-module-no-link src="${SRC_DIR}" target="${CONNECTION_CHECK}" /> + </target> + <target name="build-deskshare" description="Compile Deskshare Module"> <build-module src="${SRC_DIR}" target="${DESKSHARE}" /> <echo message="Copying deskshare applet for Deskshare Module" /> @@ -502,7 +508,8 @@ build-webcam-preview-standalone, build-webcam-view-standalone, compile-bbb" description="Build BBB client skipping compiling of locales"/> <target name="clean-build-all" depends="clean, init-ant-contrib, generate-html-wrapper, compile-deskshare-standalone, build-polling, build-mic-check, - build-cam-check, build-webcam-preview-standalone, build-webcam-view-standalone, compile-bbb, branding, branding-black" + build-cam-check, build-conn-check, build-webcam-preview-standalone, build-webcam-view-standalone, + compile-bbb, branding, branding-black" description="Build BBB client including locales"/> <target name="modules" depends="init-ant-contrib, generate-html-wrapper, compile-deskshare-standalone, build-webcam-preview-standalone, build-webcam-view-standalone, compile-bbb" diff --git a/bigbluebutton-client/resources/prod/check/bbb-check.html b/bigbluebutton-client/resources/prod/check/bbb-check.html index 4c20afd55a..696ef41497 100755 --- a/bigbluebutton-client/resources/prod/check/bbb-check.html +++ b/bigbluebutton-client/resources/prod/check/bbb-check.html @@ -11,6 +11,7 @@ <script type="text/javascript" src="../swfobject/swfobject.js"></script> <script type="text/javascript"> swfobject.registerObject("MicrophoneCheck", "11", "expressInstall.swf"); + swfobject.registerObject("RTMPConnCheck", "11", "expressInstall.swf"); </script> <script type="text/javascript" src="../lib/jquery-1.5.1.min.js" language="javascript"></script> <script type="text/javascript" src="lib/deployJava.js" language="javascript"></script> @@ -36,6 +37,8 @@ <button type="button" onclick="bbbCheckStartTestMic()">Start Mic</button> <button type="button" onclick="bbbCheckStopTestMic()">Stop Mic</button> <button type="button" onclick="bbbCheckShowCamSettings()">show cam settings</button> + <button type="button" onclick="bbbCheckTestRTMPConnection('192.168.0.249', 'video/portTest')">Test RTMP</button> + <button type="button" onclick="bbbCheckTestSocketConnection('192.168.0.249', 9123)">Test Deskshare conn</button> </div> <div id="webcamview" style="background-color:#FFD700;height:215px;width:138px;float:left;"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540002" width="215" height="138" id="MicrophoneCheck" name="MicrophoneCheck" align="middle"> @@ -59,5 +62,27 @@ <!--<![endif]--> </object> </div> + <div id="webcamview" style="background-color:#FFD700;height:215px;width:138px;float:left;"> + <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540002" width="215" height="138" id="RTMPConnCheck" name="RTMPConnCheck" align="middle"> + <param name="movie" value="http://192.168.0.249/client/RTMPConnCheck.swf?v=VERSION" /> + <param name="quality" value="high" /> + <param name="allowfullscreen" value="true" /> + <param name="bgcolor" value="#869ca7" /> + <param name="wmode" value="window" /> + <param name="allowScriptAccess" value="always" /> + <!--[if !IE]>--> + <object type="application/x-shockwave-flash" data="http://192.168.0.249/client/RTMPConnCheck.swf?v=VERSION" width="215" height="138" align="middle"> + <param name="quality" value="high" /> + <param name="bgcolor" value="#869ca7" /> + <param name="allowScriptAccess" value="always" /> + <!--<![endif]--> + <a href="http://www.adobe.com/go/getflashplayer"> + <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> + </a> + <!--[if !IE]>--> + </object> + <!--<![endif]--> + </object> + </div> </body> </html> diff --git a/bigbluebutton-client/resources/prod/check/lib/bbb_check.js b/bigbluebutton-client/resources/prod/check/lib/bbb_check.js index 893b83247c..e22d18a92b 100755 --- a/bigbluebutton-client/resources/prod/check/lib/bbb_check.js +++ b/bigbluebutton-client/resources/prod/check/lib/bbb_check.js @@ -11,6 +11,10 @@ function getSwfObj() { return swfobject.getObjectById("MicrophoneCheck"); } + + function getConnObj() { + return swfobject.getObjectById("RTMPConnCheck"); + } BBBCheck.getFlashPlayerVersion = function() { return swfobject.getFlashPlayerVersion(); @@ -72,6 +76,22 @@ } } + BBBCheck.testRTMPConnection = function(host, app) { + var swfObj = getConnObj(); + if (swfObj) { + swfObj.testRTMPConnection(host, app); + } + } + + BBBCheck.testSocketConnection = function(host, port) { + var swfObj = getConnObj(); + if (swfObj) { + swfObj.testSocketConnection(host, port); + } + } + + + /*** Callbacks from Flash test apps **/ BBBCheck.microphoneCheckAppReady = function() { console.log("microphone check app ready."); broadcast("MicCheckAppReadyEvent"); @@ -97,6 +117,38 @@ console.log("Cam access has been allowed."); } + BBBCheck.invalidParamsForRtmpConnectionTest = function() { + console.log("Invalid host or app for rtmp connection test."); + } + + BBBCheck.rtmpConnectionTestSuccess = function(rtmp, server, application) { + console.log("Connection succeeded using rtmp[" + rtmp + "]"); + } + + BBBCheck.rtmpConnectionTestFailed = function(host, app) { + console.log("Failed to connect to [" + host + "][" + app + "]"); + } + + BBBCheck.socketConnTestFailed = function(host, port) { + console.log("Failed to connect to [" + host + "][" + port + "]"); + } + + BBBCheck.socketConnTestClosed = function(host, port) { + console.log("Connection closed to [" + host + "][" + port + "]"); + } + + BBBCheck.socketConnTestSuccess = function(host, port) { + console.log("Connection success to [" + host + "][" + port + "]"); + } + + BBBCheck.socketConnTestIOError = function(host, port) { + console.log("Connection IO error to [" + host + "][" + port + "]"); + } + + BBBCheck.socketConnTestSecurityError = function(host, port) { + console.log("Connection security error to [" + host + "][" + port + "]"); + } + /* *********************************************************************************** * Broadcasting of events to 3rd-party apps. *************************************************************************************/ diff --git a/bigbluebutton-client/resources/prod/check/lib/pre_flight_check.js b/bigbluebutton-client/resources/prod/check/lib/pre_flight_check.js index 7b86b381e0..33f91dbfae 100755 --- a/bigbluebutton-client/resources/prod/check/lib/pre_flight_check.js +++ b/bigbluebutton-client/resources/prod/check/lib/pre_flight_check.js @@ -41,3 +41,11 @@ var bbbCheckStopTestMic = function() { var bbbCheckShowCamSettings = function() { BBBCheck.showCamSettings(); } + +var bbbCheckTestRTMPConnection = function(host, app) { + BBBCheck.testRTMPConnection(host, app); +} + +var bbbCheckTestSocketConnection = function(host, port) { + BBBCheck.testSocketConnection(host, port); +} diff --git a/bigbluebutton-client/src/RTMPConnCheck.mxml b/bigbluebutton-client/src/RTMPConnCheck.mxml new file mode 100755 index 0000000000..87149fbd15 --- /dev/null +++ b/bigbluebutton-client/src/RTMPConnCheck.mxml @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" + applicationComplete="appInit()"> + <mx:Script> + <![CDATA[ + private function appInit():void { + if (ExternalInterface.available) { + ExternalInterface.addCallback("testRTMPConnection", handleTestRTMPConnectionRequest); + ExternalInterface.addCallback("testSocketConnection", handleTestSocketRequest); + } + + // Tell out JS counterpart that we are ready. + if (ExternalInterface.available) { + ExternalInterface.call("BBBCheck.RTMPConnCheckAppReady"); + } + } + + private var rtmpTimer:Timer = null; + private var netConnection:NetConnection = null; + private const connectionTimeout:int = 5000; + + private var server:String; + private var application:String; + + private function handleTestRTMPConnectionRequest(host:String, app:String):void { + server = host; + application = app; + + if ((server != null || server != "") && (application != null || application != "")) { + connect(true); + } else { + ExternalInterface.call("BBBCheck.invalidParamsForRtmpConnectionTest"); + } + } + + private var rtmp:Boolean; + + private function connect(testRTMP:Boolean):void { + rtmp = testRTMP; + + netConnection = new NetConnection(); + netConnection.client = this; + + netConnection.addEventListener(NetStatusEvent.NET_STATUS, connectionHandler); + var connStr:String = (rtmp ? "rtmp:" : "rtmpt:") + "//" + server + "/" + application; + trace("Connecting to [" + connStr + "]"); + netConnection.connect(connStr); + + if (rtmp) { + rtmpTimer = new Timer(connectionTimeout, 1); + rtmpTimer.addEventListener(TimerEvent.TIMER_COMPLETE, rtmpTimeoutHandler); + rtmpTimer.start(); + } + } + + private function rtmpTimeoutHandler(e:TimerEvent):void { + netConnection.close(); + netConnection = null; + + connect(false); + } + + private function connectionHandler(e:NetStatusEvent):void { + if (rtmpTimer) { + rtmpTimer.stop(); + rtmpTimer = null; + } + + if ("NetConnection.Connect.Success" == e.info.code) { + // We've managed to connect to Red5. Inform requester that we connected + // using either RTMP or RTMPT. + ExternalInterface.call("BBBCheck.rtmpConnectionTestSuccess", rtmp, server, application); + } else if ("NetConnection.Connect.Failed" == e.info.code) { + // Check if this event is for the RTMPT test. If so, reply that + // we cannot connect to Red5 using RTMP or RTMPT. If this is for + // RTMP, we just swallow and let the timeout occur to test using + // RTMPT. (ralam apr 17, 2013) + if (!rtmp) { + ExternalInterface.call("BBBCheck.rtmpConnectionTestFailed", server, application); + } + } + } + + private var socket:Socket; + private var socketTimer:Timer = null; + private var socketHost:String; + private var socketPort:uint; + + private function handleTestSocketRequest(host:String, port:uint):void { + configureListeners(); + trace("Socket test for [" + host + "] [" + port + "]"); + + if (host && port) { + socket = new Socket(); + socket.connect(host, port); + socketTimer = new Timer(connectionTimeout, 1); + socketTimer.addEventListener(TimerEvent.TIMER_COMPLETE, socketTimeoutHandler); + socketTimer.start(); + } + } + + private function stopSocketTimer():void { + if (socketTimer) { + socketTimer.stop(); + socketTimer = null; + } + } + + private function socketTimeoutHandler(e:TimerEvent):void { + socket.close(); + socket = null; + + ExternalInterface.call("BBBCheck.socketConnTestFailed", socketHost, socketPort); + } + + private function closeSocket():void { + socket.close(); + socket = null; + } + + private function configureListeners():void { + addEventListener(Event.CLOSE, closeHandler); + addEventListener(Event.CONNECT, connectHandler); + addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); + addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + } + + private function closeHandler(event:Event):void { + ExternalInterface.call("BBBCheck.socketConnTestClosed", socketHost, socketPort); + } + + private function connectHandler(event:Event):void { + ExternalInterface.call("BBBCheck.socketConnTestSuccess", socketHost, socketPort); + closeSocket(); + } + + private function ioErrorHandler(event:IOErrorEvent):void { + ExternalInterface.call("BBBCheck.socketConnTestIOError", socketHost, socketPort); + } + + private function securityErrorHandler(event:SecurityErrorEvent):void { + ExternalInterface.call("BBBCheck.socketConnTestSecurityError", socketHost, socketPort); + } + + 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 + trace("bandwidth = " + p_bw + " Kbps."); + } + + ]]> + </mx:Script> +</mx:Application> -- GitLab