ndt-dev - [ndt-dev] [ndt] r1122 committed - Refactor external calls to allow JS callbacks to be grouped within an ...
Subject: NDT-DEV email list created
List archive
[ndt-dev] [ndt] r1122 committed - Refactor external calls to allow JS callbacks to be grouped within an ...
Chronological Thread
- From:
- To:
- Subject: [ndt-dev] [ndt] r1122 committed - Refactor external calls to allow JS callbacks to be grouped within an ...
- Date: Fri, 11 Jul 2014 21:38:22 +0000
Revision: 1122
Author:
Date: Fri Jul 11 21:37:41 2014 UTC
Log: Refactor external calls to allow JS callbacks to be grouped within an object.
http://code.google.com/p/ndt/source/detail?r=1122
Modified:
/branches/flash-scriptability/flash-client/src/Main.as
/branches/flash-scriptability/flash-client/src/NDTConstants.as
/branches/flash-scriptability/flash-client/src/NDTUtils.as
=======================================
--- /branches/flash-scriptability/flash-client/src/Main.as Mon Jun 30 20:05:07 2014 UTC
+++ /branches/flash-scriptability/flash-client/src/Main.as Fri Jul 11 21:37:41 2014 UTC
@@ -30,6 +30,7 @@
public static var client_application:String = NDTConstants.CLIENT_ID;
public static var ndt_description:String = NDTConstants.NDT_DESCRIPTION;
public static var jsonSupport:Boolean = true;
+ public static var js_callback_prefix:String = null;
public function Main():void {
if (stage)
=======================================
--- /branches/flash-scriptability/flash-client/src/NDTConstants.as Fri Mar 21 10:33:50 2014 UTC
+++ /branches/flash-scriptability/flash-client/src/NDTConstants.as Fri Jul 11 21:37:41 2014 UTC
@@ -162,6 +162,7 @@
public static const HTML_LOCALE:String = "Locale";
public static const HTML_USERAGENT:String = "UserAgentString";
public static const HTML_SERVER_HOSTNAME:String = "ServerHostname";
+ public static const HTML_JS_CALLBACK_PREFIX:String = "JSCallbackObject";
// Names of NDT variables sent by the server.
public static const MSSSENT:String = "MSSSent";
=======================================
--- /branches/flash-scriptability/flash-client/src/NDTUtils.as Fri Jul 11 01:42:49 2014 UTC
+++ /branches/flash-scriptability/flash-client/src/NDTUtils.as Fri Jul 11 21:37:41 2014 UTC
@@ -34,16 +34,24 @@
* pass to the JS function
*/
public static function callExternalFunction(
- functionName:String, ... args):void {
+ functionName:String, ... args):String {
if (!ExternalInterface.available)
- return;
+ return null;
+ var prefix:String = "";
+ var result:String = null;
+ if (Main.js_callback_prefix) {
+ prefix = Main.js_callback_prefix + ".";
+ }
try {
switch (args.length) {
- case 0: ExternalInterface.call(functionName);
+ case 0: result = ExternalInterface.call(prefix + functionName);
break;
- case 1: ExternalInterface.call(functionName, args[0]);
+ case 1: result = ExternalInterface.call(prefix + functionName,
+ args[0]);
break;
- case 2: ExternalInterface.call(functionName, args[0], args[1]);
+ case 2: result = ExternalInterface.call(prefix + functionName,
+ args[0],
+ args[1]);
break;
}
} catch (e:Error) {
@@ -54,14 +62,16 @@
// to invoke JS callbacks. Without this check we can
// recurse infinitely.
if (functionName != "appendDebugOutput") {
- TestResults.appendDebugMsg("Failed to call " + functionName + ": "
+ TestResults.appendDebugMsg("Failed to call "+(prefix+functionName)+":"
+ e.toString());
}
}
+ return result;
}
/**
- * Function that initializes the NDT server variable set directly through JS.
+ * Function that exposes the functionality of setting
+ * the NDT server variable directly through JS.
*/
public static function setHost(hostname:String):String {
var js_server_hostname:String = hostname;
@@ -81,7 +91,7 @@
*/
public static function hostnameFromJS():String {
try {
- var js_server_hostname:String = ExternalInterface.call("getNDTServer");
+ var js_server_hostname:String = callExternalFunction("getNDTServer");
if (js_server_hostname) {
TestResults.appendDebugMsg(
"Initialized server from JavaScript. Server hostname:"
@@ -118,6 +128,13 @@
}
// else keep the default value (NDTConstants.SERVER_HOSTNAME).
+ if (NDTConstants.HTML_JS_CALLBACK_PREFIX in paramObject) {
+ Main.js_callback_prefix =
+ paramObject[NDTConstants.HTML_JS_CALLBACK_PREFIX];
+ TestResults.appendDebugMsg("Initialized JS object from HTML. Object: "
+ + Main.js_callback_prefix);
+ }
+
if (!ExternalInterface.available)
return;
@@ -141,7 +158,7 @@
try {
var js_client_application:String =
- ExternalInterface.call("getClientApplication");
+ callExternalFunction("getClientApplication");
if (js_client_application) {
Main.client_application = js_client_application;
TestResults.appendDebugMsg(
@@ -155,8 +172,7 @@
}
try {
- var ndt_description:String =
- ExternalInterface.call("getNDTDescription");
+ var ndt_description:String = callExternalFunction("getNDTDescription");
if (ndt_description) {
Main.ndt_description = ndt_description;
TestResults.appendDebugMsg(
- [ndt-dev] [ndt] r1122 committed - Refactor external calls to allow JS callbacks to be grouped within an ..., ndt, 07/11/2014
Archive powered by MHonArc 2.6.16.