views:

97

answers:

2

Hi !

Let's get directly to the problem :

I'm actually doing a firefox extension in which i would like to implement the jWebsocket API in order to build a small chat. I got my main script file, named test.js, and the jWebsocket lib into a js folder. Just for you to know, this is my first firefox extension ever.

So in my XUL file I got this (for the script part only of course, the interface code is not shown) :

    <overlay id="test-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;
  <script type="application/x-javascript" src="chrome://test/content/test.js" />
  <script type="application/x-javascript" src="chrome://test/content/js/jwebsocket.js" />

jwebsocket.js being the file I need to call according to jWebsocket website.

In my main script file test.js I start with :

if (jws.browserSupportsWebSockets()) 
{
  jWebSocketClient = new jws.jWebSocketJSONClient();
} 
else 
{
  var lMsg = jws.MSG_WS_NOT_SUPPORTED;
  alert(lMsg);
}

jws being the namespace created into the jwebsocket.js file.

Of course I've got the required stand-alone server running in background, and working.

So from what I understood looking on various websites, is that if a js file is loaded into the javascript allocated memory space (with the tag), all namespace/function should be available between each file. But this was mostly for HTML-oriented issues, so I'm not sure if it applies to XUL/Firefox environment.

But the script keep failing at the first jws call.

Any ideas on what goes wrong here ? I'm stuck for 2 days now :/

A: 

EDIT: sry for double post

colon3l
A: 

Yes, is the same of HTML developing, you have your namespace avaiable between each XUL file. Take a look here for namespacing in firefox extensions.

What error do you get?

Edit:

Do you have initialized your jws object before to call browserSupportsWebSockets() ?

Like Pointy said, you need to load test.js after your jwebsocket.js file.

Manuel Bitto
Thank you for the link, the jwebsocket namespace seems to be well-formed.And I do not get any error, I placed an *alert* before and after the block of code I posted, the first one works, not the second, and the code is just supposed to create an *jWebSocketJSONClient*.
colon3l
Place the alert inside if and else, before the assignation, so you can get what the code executes
Manuel Bitto
Well...no I didn't. How can I do that ? Sry I am not really into javascript. (But the jwebsocket is now loaded before, but as I said no changes)EDIT : no alert fires up between if or else, so it must fail when calling the *jws.browserSupportsWebSockets()*
colon3l
I think it would be better if you post an example of how the jws object is structured.
Manuel Bitto
The source file can be found here : http://bit.ly/ccDz3B
colon3l
I think that code wouldn't run in a firefox extension simply including it. In firefox extensions you are subject to some restrictions that could block some parts of that code.
Manuel Bitto
Arg :/ What make you think that, regarding the jwebsocket.js code ? (I'm just being curious) Or do you have any links relative to those "restrictions" ? Anyway thanks for your help, it is appreciated :)
colon3l