Improve check for node.js in examples. Add mechanism for clients to increase 
stack as well as total memory - NB this feature requires emscripten fix only 
recently applied to incoming so may not be available in SDK yet

git-svn-id: 
https://svn.apache.org/repos/asf/qpid/proton/branches/fadams-javascript-binding@1627942
 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d8ebc7f4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d8ebc7f4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d8ebc7f4

Branch: refs/heads/master
Commit: d8ebc7f4ade39d9266ea23568cfc126a1c0e1c9f
Parents: 2cf80a9
Author: fadams <fadams@unknown>
Authored: Sat Sep 27 10:13:43 2014 +0000
Committer: fadams <fadams@unknown>
Committed: Sat Sep 27 10:13:43 2014 +0000

----------------------------------------------------------------------
 examples/messenger/javascript/client.js      |  129 +-
 examples/messenger/javascript/drain.js       |   71 +-
 examples/messenger/javascript/proxy.js       |  111 +-
 examples/messenger/javascript/qpid-config.js | 2769 +++++++++++----------
 examples/messenger/javascript/recv.js        |   79 +-
 examples/messenger/javascript/send.html      |   11 +-
 examples/messenger/javascript/send.js        |  133 +-
 examples/messenger/javascript/server.js      |   99 +-
 examples/messenger/javascript/spout.js       |  130 +-
 proton-c/bindings/javascript/README          |   36 +-
 proton-c/bindings/javascript/messenger.js    |   11 +-
 proton-c/bindings/javascript/module.js       |   32 +-
 proton-c/bindings/javascript/subscription.js |   10 +-
 tests/javascript/codec.js                    | 1050 ++++----
 tests/javascript/message.js                  |  600 +++--
 tests/javascript/soak.js                     |  132 +-
 16 files changed, 2699 insertions(+), 2704 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d8ebc7f4/examples/messenger/javascript/client.js
----------------------------------------------------------------------
diff --git a/examples/messenger/javascript/client.js 
b/examples/messenger/javascript/client.js
index 5fae391..62f9a61 100644
--- a/examples/messenger/javascript/client.js
+++ b/examples/messenger/javascript/client.js
@@ -22,84 +22,83 @@
 // Simple client for use with server.js illustrating request/response
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("client.js should be run in Node.js");
-    return;
-}
-
-var proton = require("qpid-proton");
+if (typeof process === 'object' && typeof require === 'function') {
+    var proton = require("qpid-proton");
 
-var address = "amqp://0.0.0.0";
-var subject = "UK.WEATHER";
-var replyTo = "~/replies";
-var msgtext = "Hello World!";
-var tracker = null;
-var running = true;
+    var address = "amqp://0.0.0.0";
+    var subject = "UK.WEATHER";
+    var replyTo = "~/replies";
+    var msgtext = "Hello World!";
+    var tracker = null;
+    var running = true;
 
-var message = new proton.Message();
-var messenger = new proton.Messenger();
+    var message = new proton.Message();
+    var messenger = new proton.Messenger();
 
-var pumpData = function() {
-    while (messenger.incoming()) {
-        var t = messenger.get(message);
+    var pumpData = function() {
+        while (messenger.incoming()) {
+            var t = messenger.get(message);
 
-        console.log("Reply");
-        console.log("Address: " + message.getAddress());
-        console.log("Subject: " + message.getSubject());
+            console.log("Reply");
+            console.log("Address: " + message.getAddress());
+            console.log("Subject: " + message.getSubject());
 
-        // body is the body as a native JavaScript Object, useful for most 
real cases.
-        //console.log("Content: " + message.body);
+            // body is the body as a native JavaScript Object, useful for most 
real cases.
+            //console.log("Content: " + message.body);
 
-        // data is the body as a proton.Data Object, used in this case because
-        // format() returns exactly the same representation as recv.c
-        console.log("Content: " + message.data.format());
+            // data is the body as a proton.Data Object, used in this case 
because
+            // format() returns exactly the same representation as recv.c
+            console.log("Content: " + message.data.format());
 
-        messenger.accept(t);
-        messenger.stop();
-    }
+            messenger.accept(t);
+            messenger.stop();
+        }
 
-    if (messenger.isStopped()) {
-        message.free();
-        messenger.free();
-    }
-};
-
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: node client.js [-r replyTo] [-s subject] <addr> 
(default " + address + ")");
-        console.log("Options:");
-        console.log("  -r <reply to> The message replyTo (default " + replyTo 
+ ")");
-        console.log("  -s <subject> The message subject (default " + subject + 
")");
-        process.exit(0);
-    }
+        if (messenger.isStopped()) {
+            message.free();
+            messenger.free();
+        }
+    };
+
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: node client.js [-r replyTo] [-s subject] 
<addr> (default " + address + ")");
+            console.log("Options:");
+            console.log("  -r <reply to> The message replyTo (default " + 
replyTo + ")");
+            console.log("  -s <subject> The message subject (default " + 
subject + ")");
+            process.exit(0);
+        }
 
-    for (var i = 0; i < args.length; i++) {
-        var arg = args[i];
-        if (arg.charAt(0) === '-') {
-            i++;
-            var val = args[i];
-            if (arg === '-r') {
-                replyTo = val;
-            } else if (arg === '-s') {
-                subject = val;
+        for (var i = 0; i < args.length; i++) {
+            var arg = args[i];
+            if (arg.charAt(0) === '-') {
+                i++;
+                var val = args[i];
+                if (arg === '-r') {
+                    replyTo = val;
+                } else if (arg === '-s') {
+                    subject = val;
+                }
+            } else {
+                address = arg;
             }
-        } else {
-            address = arg;
         }
     }
-}
 
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.setOutgoingWindow(1024);
-messenger.start();
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.setOutgoingWindow(1024);
+    messenger.recv(); // Receive as many messages as messenger can buffer.
+    messenger.start();
 
-message.setAddress(address);
-message.setSubject(subject);
-message.setReplyTo(replyTo);
-message.body = msgtext;
+    message.setAddress(address);
+    message.setSubject(subject);
+    message.setReplyTo(replyTo);
+    message.body = msgtext;
 
-tracker = messenger.put(message);
-messenger.recv(); // Receive as many messages as messenger can buffer.
+    tracker = messenger.put(message);
+} else {
+    console.error("client.js should be run in Node.js");
+}
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d8ebc7f4/examples/messenger/javascript/drain.js
----------------------------------------------------------------------
diff --git a/examples/messenger/javascript/drain.js 
b/examples/messenger/javascript/drain.js
index 20a7e83..04ced73 100644
--- a/examples/messenger/javascript/drain.js
+++ b/examples/messenger/javascript/drain.js
@@ -20,52 +20,51 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("drain.js should be run in Node.js");
-    return;
-}
+if (typeof process === 'object' && typeof require === 'function') {
+    var proton = require("qpid-proton");
 
-var proton = require("qpid-proton");
+    console.log("drain not implemented yet");
+    process.exit(0);
 
-console.log("drain not implemented yet");
-process.exit(0);
+    var address = "amqp://~0.0.0.0";
+    var message = new proton.Message();
+    var messenger = new proton.Messenger();
 
-var address = "amqp://~0.0.0.0";
-var message = new proton.Message();
-var messenger = new proton.Messenger();
+    var pumpData = function() {
+        while (messenger.incoming()) {
+            var t = messenger.get(message);
 
-var pumpData = function() {
-    while (messenger.incoming()) {
-        var t = messenger.get(message);
+            console.log("Address: " + message.getAddress());
+            console.log("Subject: " + message.getSubject());
+    
+            // body is the body as a native JavaScript Object, useful for most 
real cases.
+            //console.log("Content: " + message.body);
 
-        console.log("Address: " + message.getAddress());
-        console.log("Subject: " + message.getSubject());
+            // data is the body as a proton.Data Object, used in this case 
because
+            // format() returns exactly the same representation as recv.c
+            console.log("Content: " + message.data.format());
 
-        // body is the body as a native JavaScript Object, useful for most 
real cases.
-        //console.log("Content: " + message.body);
+            messenger.accept(t);
+        }
+    };
 
-        // data is the body as a proton.Data Object, used in this case because
-        // format() returns exactly the same representation as recv.c
-        console.log("Content: " + message.data.format());
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: recv <addr> (default " + address + ").");
+            process.exit(0);
+        }
 
-        messenger.accept(t);
+        address = args[0];
     }
-};
 
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: recv <addr> (default " + address + ").");
-        process.exit(0);
-    }
+    messenger.on('error', function(error) {console.log(error);});
+    messenger.on('work', pumpData);
+    messenger.recv(); // Receive as many messages as messenger can buffer.
+    messenger.start();
 
-    address = args[0];
+    messenger.subscribe(address);
+} else {
+    console.error("drain.js should be run in Node.js");
 }
 
-messenger.on('error', function(error) {console.log(error);});
-messenger.on('work', pumpData);
-messenger.start();
-
-messenger.subscribe(address);
-messenger.recv(); // Receive as many messages as messenger can buffer.
-

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d8ebc7f4/examples/messenger/javascript/proxy.js
----------------------------------------------------------------------
diff --git a/examples/messenger/javascript/proxy.js 
b/examples/messenger/javascript/proxy.js
index 2a7866b..cac5cf5 100755
--- a/examples/messenger/javascript/proxy.js
+++ b/examples/messenger/javascript/proxy.js
@@ -36,71 +36,70 @@
  */
 
 // Check if the environment is Node.js and if not log an error and exit.
-if (!exports) {
-    console.error("proxy.js should be run in Node.js");
-    return;
-}
-
-var proxy = require('./ws2tcp.js');
+if (typeof process === 'object' && typeof require === 'function') {
+    var proxy = require('./ws2tcp.js');
 
-var lport = 5673;
-var tport = lport - 1;
-var thost = '0.0.0.0';
-var method = 'ws2tcp';
+    var lport = 5673;
+    var tport = lport - 1;
+    var thost = '0.0.0.0';
+    var method = 'ws2tcp';
 
-var args = process.argv.slice(2);
-if (args.length > 0) {
-    if (args[0] === '-h' || args[0] === '--help') {
-        console.log("Usage: node proxy.js [options]");
-        console.log("Options:");
-        console.log("  -p <listen port>, --port  <listen port> (default " + 
lport + " for ws2tcp");
-        console.log("                                                   " + 
tport + " for tcp2ws)");
-        console.log("  -t <target port>, --tport <target port> (default listen 
port - 1 for ws2tcp");
-        console.log("                                                   listen 
port + 1 for tcp2ws)");
-        console.log("  -h <target host>, --thost <target host> (default " + 
thost + ")");
-        console.log("  -m <ws2tcp or tcp2ws>, --method <ws2tcp or tcp2ws> 
(default " + method + ")");
-        process.exit(0);
-    }
+    var args = process.argv.slice(2);
+    if (args.length > 0) {
+        if (args[0] === '-h' || args[0] === '--help') {
+            console.log("Usage: node proxy.js [options]");
+            console.log("Options:");
+            console.log("  -p <listen port>, --port  <listen port> (default " 
+ lport + " for ws2tcp");
+            console.log("                                                   " 
+ tport + " for tcp2ws)");
+            console.log("  -t <target port>, --tport <target port> (default 
listen port - 1 for ws2tcp");
+            console.log("                                                   
listen port + 1 for tcp2ws)");
+            console.log("  -h <target host>, --thost <target host> (default " 
+ thost + ")");
+            console.log("  -m <ws2tcp or tcp2ws>, --method <ws2tcp or tcp2ws> 
(default " + method + ")");
+            process.exit(0);
+        }
 
-    var lportSet = false;
-    var tportSet = false;
-    for (var i = 0; i < args.length; i++) {
-        var arg = args[i];
-        if (arg.charAt(0) === '-') {
-            i++;
-            var val = args[i];
-            if (arg === '-p' || arg === '--port') {
-                lport = val;
-                lportSet = true;
-            } else if (arg === '-t' || arg === '--tport') {
-                tport = val;
-                tportSet = true;
-            } else if (arg === '-h' || arg === '--thost') {
-                thost = val;
-            } else if (arg === '-m' || arg === '--method') {
-                method = val;
+        var lportSet = false;
+        var tportSet = false;
+        for (var i = 0; i < args.length; i++) {
+            var arg = args[i];
+            if (arg.charAt(0) === '-') {
+                i++;
+                var val = args[i];
+                if (arg === '-p' || arg === '--port') {
+                    lport = val;
+                    lportSet = true;
+                } else if (arg === '-t' || arg === '--tport') {
+                    tport = val;
+                    tportSet = true;
+                } else if (arg === '-h' || arg === '--thost') {
+                    thost = val;
+                } else if (arg === '-m' || arg === '--method') {
+                    method = val;
+                }
             }
         }
-    }
 
-    if (method === 'tcp2ws' && !lportSet) {
-        lport--;
-    }
+        if (method === 'tcp2ws' && !lportSet) {
+            lport--;
+        }
 
-    if (!tportSet) {
-        tport = (method === 'ws2tcp') ? lport - 1 : +lport + 1;
+        if (!tportSet) {
+            tport = (method === 'ws2tcp') ? lport - 1 : +lport + 1;
+        }
     }
-}
 
-if (method === 'tcp2ws') {
-    console.log("Proxying tcp -> ws");
-    console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
-    proxy.tcp2ws(lport, thost, tport, 'AMQPWSB10');
-} else if (method === 'ws2tcp') {
-    console.log("Proxying ws -> tcp");
-    console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
-    proxy.ws2tcp(lport, thost, tport);
+    if (method === 'tcp2ws') {
+        console.log("Proxying tcp -> ws");
+        console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
+        proxy.tcp2ws(lport, thost, tport, 'AMQPWSB10');
+    } else if (method === 'ws2tcp') {
+        console.log("Proxying ws -> tcp");
+        console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
+        proxy.ws2tcp(lport, thost, tport);
+    } else {
+        console.error("Method must be either ws2tcp or tcp2ws.");
+    }
 } else {
-    console.error("Method must be either ws2tcp or tcp2ws.");
+    console.error("proxy.js should be run in Node.js");
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to