Commit Graph

22 Commits

Author SHA1 Message Date
Joel Martin ac7bdbc22f web-socket-js (issue #37): close() when connecting
Filed this issue for this bug:
http://github.com/gimite/web-socket-js/issues/issue/37

Right now the close() call only calls __flash.close() if readyState is OPEN.
But it should really call close any time that readyState is not CLOSED or
CLOSING.

The case I ran into is when I want to do the following:
1. make a test connection
2. tell the server to setup for a connection
3. connect again

I call close on the test connection, but since it is ignored when CONNECTING,
it eventually times out with a error. But by that time I have already issued a
new connection, it causes the new connection to fail. close() should cancel
CONNECTING state too.
2010-09-11 13:52:49 -05:00
Joel Martin 071f2818a8 gimite/web-socket-js issue #35: async onclose.
Filed this bug about this issue:
http://github.com/gimite/web-socket-js/issues#issue/35

To work around the flash "recursive call" problem, WebSocket.as has
the onclose event disabled in the close() call and the javascript half
of the close() call does the onclose() call instead. This is fine, but
it needs to be asynchronous to act more like what happens with
a normal WebSockets object. The current behavior is that the onclose()
method is called inline (synchronously) when the close() is called and
this inconsistency make state handling more difficult.
2010-09-11 12:44:39 -05:00
Joel Martin 2a6018df9f web-socket-js: 9e7663771 build and remove source.
web-socket-js now has all the functionality and fixes needed for noVNC
so remove the include/as3crypto_patched directory and the
include/web-socket-js/flash-src directory (i.e. the sources for
web-socket-js). This cleans up almost 3K from the include/ directory.

Update to web-socket-js build based on upstream (gimite/web-socket-js)
9e766377188.
2010-09-08 14:57:32 -05:00
Joel Martin 2ca053affc Rebuild web-socket-js swf with gimite updates.
Bug fixes, restore RFC2817 proxy for non wss://, and handle new closing
handshake from WebSockets 76.
2010-07-02 10:50:52 -05:00
Joel Martin 1144eaa37a Add global variable option for swf location.
The problem is, you can't set WebSocket.__swfLocation before you load
web_socket.js (because it creates the WebSocket global), but you also
can't reliably set WebSocket.__swfLocation after because if you are
doing dynamic script file includes then the onload (i.e.
WebSocket.__initialize) may fire before you have a chance to set
Websocket.__swfLocation.
2010-07-02 09:54:55 -05:00
Joel Martin b9633f8bfd Import/merge gimite/web-socket-js up to da7caff96496c7d7bfb3.
Bug fixes, restore RFC2817 proxy for non wss://, and handle new
closing handshake from WebSockets 76.
2010-07-02 09:52:59 -05:00
Joel Martin 2b71a4db58 Update web-socket-js binary build and README.md
Brings it up to date with the most recent web-socket-js event handling
fixes.
2010-07-01 12:04:26 -05:00
Joel Martin bc8e3d4db7 Opera fixes and big Opera performance boost.
Add message/state pollling in web-socket-js. Since Opera tends to drop
message events, we can dramatically increase performance by polling
every now for message event data.

Also, add more direct calls to update readyState so that it's not
missed when Opera drops events.
2010-07-01 11:54:44 -05:00
Joel Martin 4a96178307 Better web-socket-js dataQueue reset.
At connect and close time instead of initialization time.
2010-07-01 10:35:03 -05:00
Joel Martin 9479c72083 web-socket-js event fixes.
When using web-socket-js, the onopen event may happen inline so the
caller may not have time to set onopen before the event fires. In this
case set a short timeout and try again. In particular this affects
Opera most of the time.

Also, to get around Opera event droppings, always read the readyState
directly instead of relying on the local readyState variable to be
correct (which it isn't if stateChange event were dropped).
2010-07-01 10:32:14 -05:00
Joel Martin a93c955538 Opera works! Fix message event drops/reorders.
Instead of relying on FABridge AS -> JS event delivery, we just use
the events to notify JS of pending data. The message handler then
calls the AS readSocketData routine which sends back an array of
the pending WebSocket frames.

There is still a minor bug somewhere that happens after the first
connect where the web-socket-js throws an "INVALID_STATE_ERR: Web
Socket connection has not been established". But, Opera is now usable
and we should be able to drop the packet sequence numbering and
re-ordering code.

Another minor issue to better support Opera is to move JS script
includes to the <head> of the page instead of after the body.
2010-07-01 09:53:38 -05:00
Joel Martin 486cd527f2 Support WebSockets 76 (hixie-76, hybi-00).
Looks like disabling web-socket-js debug messages by default that we
get a minor speedup.

Python proxy should support both 75 and 76 (00) modes. Also, update ws
test to more reliably hit the WebSockets ordering/drop issue.
2010-06-24 17:04:57 -05:00
Joel Martin 7dfa20b8fd Remove invalid pos check from web-socket-js. 2010-06-24 17:01:58 -05:00
Joel Martin 094b489b76 Missed change web-socket-js to dd80a1807758abfab4a0fde840f94c5d649e4a24. 2010-06-24 17:00:41 -05:00
Joel Martin 2ddd6214a5 Add web-socket-js debug flag and default to off. 2010-06-24 16:59:53 -05:00
Joel Martin 76053e2bae Squelch MD5.as build warnings. 2010-06-24 16:58:24 -05:00
Joel Martin 35f5b11ce5 Update gimite/web-socket-js to dd80a1807758abfab4a0fde840f94c5d649e4a24 2010-06-24 12:42:34 -05:00
Joel Martin 507b473a2e Test non-base64 (straight UTF-8) encoding.
Also add a wsencoding test client/server program to test send a set of
values between client and server and vice-versa to test encodings.

Not turned on by default.

Add support for encode/decode of UTF-8 in the proxy. This leverages
the browser for decoding the WebSocket stream directly instead of
doing base64 decode in the browser itself.

Unfortunately, in Chrome this has negligible impact (round-trip time
is increased slightly likely due to extra python processing).

In firefox, due to the use of the flash WebSocket emulator the
performance is even worse. This is because it's really annoying to get
the flash WebSocket emulator to properly decode a UTF-8 bytestream.
The problem is that the readUTFBytes and readMultiByte methods of an
ActionScript ByteArray don't treat 0x00 correctly. They return
a string that ends at the first 0x00, but the index into the ByteArray
has been advanced by however much you requested.

This is very silly for two reasons: ActionScript (and Javascript)
strings can contain 0x00 (they are not null terminated) and second,
UTF-8 can legitimately contain 0x00 values. Since UTF-8 is not
constant width there isn't a great way to determine if those methods
in fact did encounter a 0x00 or they just read the number of bytes
requested.

Doing manual decoding using readUTFByte one character at a time slows
things down quite a bit. And to top it all off, those methods don't
support the alternate UTF-8 encoding for 0x00 ("\xc0\x80"). They also
just treat that encoding as the end of string too.

So to get around this, for now I'm encoding zero as 256 ("\xc4\x80")
and then doing mod 256 in Javascript. Still doesn't result in much
benefit in firefox.

But, it's an interesting approach that could use some more exploration
so I'm leaving in the code in both places.
2010-05-28 15:39:38 -05:00
Joel Martin d38406e6b5 Fix web-socket-js: encode sent data across FABridge. 2010-05-28 15:34:54 -05:00
Joel Martin 8fe2c2f915 Fix web-socket-js loading issue. 2010-05-17 17:11:13 -05:00
Joel Martin adfe6ac166 Support for SSL/TLS ('wss://') on both sides.
On the client side, this adds the as3crypto library to web-socket-js
so that the WebSocket 'wss://' scheme is supported which is WebSocket
over SSL/TLS.

Couple of downsides to the fall-back method:

    - This balloons the size of the web-socket-js object from about 12K to 172K.

    - Getting it working required disabling RFC2718 web proxy support
      in web-socket-js.

    - It makes the web-socket-js fallback even slower with the
      encryption overhead.

The server side (wsproxy.py) uses python SSL support. The proxy
automatically detects the type of incoming connection whether flash
policy request, SSL/TLS handshake ('wss://') or plain socket
('ws://').

Also added a check-box to the web page to enable/disabled 'wss://'
encryption.
2010-04-30 16:41:09 -05:00
Joel Martin d920595453 Import web-socket-js: a0fb3933ce5c824bcb882f5a1cf87e46de773ea8
web-socket-js is a flash based WebSockets emulator.

From: http://github.com/gimite/web-socket-js
2010-04-17 17:23:31 -05:00