You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by Fraser Adams <fr...@blueyonder.co.uk> on 2014/09/01 20:45:46 UTC

Re: javascript binding in a browser

Hi again Ernie,
I've just committed a few improvements.

In terms of debugging if you specify
cmake .. -DCMAKE_BUILD_TYPE=Debug
or
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo

it will do a build with no JavaScript optimisations and no closure 
compiler so any JavaScript errors will be a bit more human readable. The 
default build does full Clang optimisations and JavaScript/asm.js 
optimisations and minifies/optimises with the closure compiler.

I added code to the status and isBuffered methods that checks for a null 
tracker being passed, and if so they now retrieve the outgoing tracker 
and use that.

I've also added a soak test and a little send.html

I need to take a look at error handling - if I try to send when there's 
no receiver it gets in a state where it won't subsequently send messages 
when the receiver is restarted. I might just need to stop and restart 
Messenger - TBH I can't claim to really understand the Messenger API.

Hope that you are having fun with this stuff.
Frase


On 30/08/14 16:25, Ernest Allen wrote:
> Hi Fraser,
> I'm trying to run the proton javascript bindings from within a browser. I'm getting various errors depending on the way I'm doing it and I was hoping you could shed some light on the correct approach.
> I have node recv.js running in a separate window.
>
> The first way I tried was just including proton.js directly. When I load the page the console shows the following for the HTML listed below:
> pre-main prep time: 6 ms
> proton is [object Object]
> before put
> Uncaught TypeError: Cannot read property 'fa' of null
> Uncaught TypeError: Cannot read property 'fa' of null
>
> Here is the HTML:
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
>
> <head>
> 	<title>An XHTML 1.0 Strict standard template</title>
> 	<meta http-equiv="content-type"
> 		content="text/html;charset=utf-8" />
>
> <script type="text/javascript" src="../../../node_modules/qpid-proton/lib/proton.js"></script>
>
> <script type="text/javascript">
> //<![CDATA[
>
> console.log("proton is " + window.proton);
> var address = "amqp://0.0.0.0";
> var subject = "BrowserMessage";
> var msgtext = "Hello From Browser!";
> var tracker = null;
> var running = true;
>
> var message = new proton.Message();
> var messenger = new proton.Messenger();
>
> var pumpData = function() {
>      var status = messenger.status(tracker);
>      if (status != proton.Status.PENDING) {
>          if (running) {
>              messenger.stop();
>              running = false;
>          }
>      }
>
>      if (messenger.isStopped()) {
>          message.free();
>          messenger.free();
>      }
> };
>
> messenger.on('error', function(error) {console.log("this is the error" + error);});
> messenger.on('work', pumpData);
> messenger.setOutgoingWindow(1024);
> messenger.start();
>
> message.setAddress(address);
> message.setSubject(subject);
> message.body = msgtext;
>
> console.log("before put");
> messenger.put(message);
>
> 	
> //]]>
> </script>
> </head>
>
> <body>
> </body>
>
> </html>
>
> The output in the window running node recv.js is:
> [0x535398]:ERROR[-2] AMQP header mismatch: '' (connection aborted)
>
> CONNECTION ERROR connection aborted (remote)
>
>
>
> When I browserify the proton.js into qpid-proton-browser.js and load that file instead, I get the following when the page loads:
> Uncaught TypeError: Cannot read property 'replace' of undefined
> proton is undefined
> Uncaught ReferenceError: proton is not defined
>
> The Uncaught TypeError is due to a referece to "process.argv[1]". If I manually edit the qpid-proton-browser.js file to define all the process properties that it wants, I still get the "proton is undefined" error.
>
> Do you know what I'm doing wrong?
>
> Thanks,
> -Ernie


Re: javascript binding in a browser

Posted by Ernest Allen <ea...@redhat.com>.
Hi Fraser,

Lots of great info. Thanks for being so thorough in your explanations, it really helps. After adding in the missing "tracker=", everything works as expected.

What I meant by browserify the proton.js file was the "browserify" utility (http://browserify.org/). I incorrectly thought my problem was that the proton.js file needed to be modified to run in a browser environment. That utility will bundle all "required" modules into a single file along with the calling javascript. As it turns out, your module is already stand-alone and works in either environment. 

I'll grab your latest and use that in my experiments. Thanks again for the help and the excellent work. It is fun the rediscover javascript again.
-Ernie


----- Original Message -----
From: "Fraser Adams" <fr...@blueyonder.co.uk>
To: proton@qpid.apache.org
Sent: Monday, September 1, 2014 2:45:46 PM
Subject: Re: javascript binding in a browser

Hi again Ernie,
I've just committed a few improvements.

In terms of debugging if you specify
cmake .. -DCMAKE_BUILD_TYPE=Debug
or
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo

it will do a build with no JavaScript optimisations and no closure 
compiler so any JavaScript errors will be a bit more human readable. The 
default build does full Clang optimisations and JavaScript/asm.js 
optimisations and minifies/optimises with the closure compiler.

I added code to the status and isBuffered methods that checks for a null 
tracker being passed, and if so they now retrieve the outgoing tracker 
and use that.

I've also added a soak test and a little send.html

I need to take a look at error handling - if I try to send when there's 
no receiver it gets in a state where it won't subsequently send messages 
when the receiver is restarted. I might just need to stop and restart 
Messenger - TBH I can't claim to really understand the Messenger API.

Hope that you are having fun with this stuff.
Frase


On 30/08/14 16:25, Ernest Allen wrote:
> Hi Fraser,
> I'm trying to run the proton javascript bindings from within a browser. I'm getting various errors depending on the way I'm doing it and I was hoping you could shed some light on the correct approach.
> I have node recv.js running in a separate window.
>
> The first way I tried was just including proton.js directly. When I load the page the console shows the following for the HTML listed below:
> pre-main prep time: 6 ms
> proton is [object Object]
> before put
> Uncaught TypeError: Cannot read property 'fa' of null
> Uncaught TypeError: Cannot read property 'fa' of null
>
> Here is the HTML:
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
>
> <head>
> 	<title>An XHTML 1.0 Strict standard template</title>
> 	<meta http-equiv="content-type"
> 		content="text/html;charset=utf-8" />
>
> <script type="text/javascript" src="../../../node_modules/qpid-proton/lib/proton.js"></script>
>
> <script type="text/javascript">
> //<![CDATA[
>
> console.log("proton is " + window.proton);
> var address = "amqp://0.0.0.0";
> var subject = "BrowserMessage";
> var msgtext = "Hello From Browser!";
> var tracker = null;
> var running = true;
>
> var message = new proton.Message();
> var messenger = new proton.Messenger();
>
> var pumpData = function() {
>      var status = messenger.status(tracker);
>      if (status != proton.Status.PENDING) {
>          if (running) {
>              messenger.stop();
>              running = false;
>          }
>      }
>
>      if (messenger.isStopped()) {
>          message.free();
>          messenger.free();
>      }
> };
>
> messenger.on('error', function(error) {console.log("this is the error" + error);});
> messenger.on('work', pumpData);
> messenger.setOutgoingWindow(1024);
> messenger.start();
>
> message.setAddress(address);
> message.setSubject(subject);
> message.body = msgtext;
>
> console.log("before put");
> messenger.put(message);
>
> 	
> //]]>
> </script>
> </head>
>
> <body>
> </body>
>
> </html>
>
> The output in the window running node recv.js is:
> [0x535398]:ERROR[-2] AMQP header mismatch: '' (connection aborted)
>
> CONNECTION ERROR connection aborted (remote)
>
>
>
> When I browserify the proton.js into qpid-proton-browser.js and load that file instead, I get the following when the page loads:
> Uncaught TypeError: Cannot read property 'replace' of undefined
> proton is undefined
> Uncaught ReferenceError: proton is not defined
>
> The Uncaught TypeError is due to a referece to "process.argv[1]". If I manually edit the qpid-proton-browser.js file to define all the process properties that it wants, I still get the "proton is undefined" error.
>
> Do you know what I'm doing wrong?
>
> Thanks,
> -Ernie