Skip to content

Commit

Permalink
Implemented url property and documented what's implemented and what's…
Browse files Browse the repository at this point in the history
… not.
  • Loading branch information
aslakhellesoy committed Feb 4, 2011
1 parent 2fce481 commit 20ecbfc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
38 changes: 30 additions & 8 deletions README.textile
Expand Up @@ -4,14 +4,36 @@ This is a (temporary) fork of HTMLUnit with the purpose of adding WebSocket supp

I didn't use git-svn as I couldn't get it to work. This means this fork won't be kept in sync with the official HTMLUnit in Subversion. Instead, a complete patch will be sent to the HTMLUnit project when WebSocket support is good enough.

Currently the following callbacks are implemented:
HTMLUnit's issue tracker has an "open ticket":https://sourceforge.net/tracker/?func=detail&atid=448269&aid=3026502&group_id=47038 for WebSocket support, but I'm not aware that anyone else has started working on it yet.
If you have comments and suggestions, please use this project's issue tracker instead of sending me personal messages, so that other interested people can join the discussion.

* <code>onopen</code>
* <code>onmessage</code>
h2. API

There is already an "open ticket":https://sourceforge.net/tracker/?func=detail&atid=448269&aid=3026502&group_id=47038 in HTMLUnit's issue tracker, but I'm not aware that anyone else has started working on it yet.
The status of the API implementation is:

If you have comments and suggestions, please use this project's issue tracker instead of sending me personal messages, so that other interested people can join the discussion.
h3. Constructors

* <code>WebSocket(url)</code>: *Implemented*
* <code>WebSocket(url, protocols)</code>: Not Implemented

h3. Event Handlers

* <code>onopen</code>: *Implemented*
* <code>onmessage</code>: *Implemented*
* <code>onerror</code>: Not Implemented
* <code>onclose</code>: Not Implemented

h3. Readonly Properties

* <code>url</code>: *Implemented*
* <code>readyState</code>: Not Implemented
* <code>bufferedAmount</code>: Not Implemented
* <code>protocol</code>: Not Implemented

h3. Functions

* <code>send</code>: *Implemented*
* <code>close</code>: *Implemented*

h2. Hacking

Expand All @@ -32,8 +54,8 @@ I may switch to https://github.com/TooTallNate/Java-WebSocket or any other libra

h2. Todos

Currently the WebSocket must be closed in Javascript, or your JUnit tests will hang. Comment out the <code>ws.close();</code> in <code>com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest</code> to see this.
# Implement the entire Javascript API
# Find a way to close al websockets if the page doesn't do it itself.

Currently the WebSocket must be closed in Javascript, or your JUnit tests will hang. Comment out the <code>ws.close();</code> in <code>com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest</code> to see this.
I haven't found a way to work around this, so contributions are welcome.

The Javascript API in <code>com.gargoylesoftware.htmlunit.javascript.host.WebSocket</code> is not fully implemented yet. For example, <code>readyState</code> is not set, <code>onclose</code> and <code>onerror</code> are not called etc.
Expand Up @@ -38,8 +38,10 @@ public class WebSocket extends SimpleScriptable {
private int readerId;
private HtmlPage page;
private JavaScriptEngine jsEngine;
private Object urlParam;

public void jsConstructor(Object urlParam) throws IOException, URISyntaxException {
this.urlParam = urlParam;
page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage();
jsEngine = page.getWebClient().getJavaScriptEngine();
final URI url = page.getFullyQualifiedUrl(Context.toString(urlParam)).toURI();
Expand Down Expand Up @@ -81,6 +83,10 @@ public String toString() {
readerId = getWindow().getWebWindow().getJobManager().addJob(job, page);
}

public Object jsxGet_url() {
return urlParam;
}

public int jsxGet_readyState() {
return readyState;
}
Expand Down
Expand Up @@ -3121,6 +3121,7 @@
<class classname="com.gargoylesoftware.htmlunit.javascript.host.WebSocket"
jsConstructor="jsConstructor" JSObject="true">
<doclink url="http://dev.w3.org/html5/websockets/" descr="W3C WebSocket API"/>
<property name="url" readable="true" writable="false"/>
<property name="readyState" readable="true" writable="false"/>
<property name="bufferedAmount" readable="true" writable="false"/>
<property name="onopen" readable="true" writable="true"/>
Expand Down

0 comments on commit 20ecbfc

Please sign in to comment.