diff options
author | Joel Martin <jmartin@sentryds.com> | 2011-05-02 17:30:38 -0500 |
---|---|---|
committer | Joel Martin <jmartin@sentryds.com> | 2011-05-02 17:30:38 -0500 |
commit | 20c16e64b46cb271374438140315cbc115c67501 (patch) | |
tree | 6bda9f9a21a7f25c16063538030ea2e8e2ca3b30 | |
parent | 8b52ec47560c6d4cfd3da996f5861a4f1696fe88 (diff) | |
download | web-socket-js-20c16e64b46cb271374438140315cbc115c67501.tar.gz |
Fix protocol attribute handling.
- First, the protocol parameter to open should accept a list or
protocols (either as a comma separate string or an array of
strings).
- Second, the chosen protocol should be reported back to and set as
the protocol attribute in the WebSocket instance object itself.
-rw-r--r-- | flash-src/WebSocket.as | 16 | ||||
-rw-r--r-- | flash-src/WebSocketMain.as | 1 | ||||
-rw-r--r-- | web_socket.js | 3 |
3 files changed, 16 insertions, 4 deletions
diff --git a/flash-src/WebSocket.as b/flash-src/WebSocket.as index 0cbbe8b..5373b90 100644 --- a/flash-src/WebSocket.as +++ b/flash-src/WebSocket.as @@ -120,6 +120,10 @@ public class WebSocket extends EventDispatcher { public function getReadyState():int { return this.readyState; } + + public function getProtocol():String { + return this.protocol; + } public function send(encData:String):int { var data:String = decodeURIComponent(encData); @@ -324,10 +328,14 @@ public class WebSocket extends EventDispatcher { onError("origin doesn't match: '" + resOrigin + "' != '" + origin + "'"); return false; } - if (protocol && header["sec-websocket-protocol"] != protocol) { - onError("protocol doesn't match: '" + - header["websocket-protocol"] + "' != '" + protocol + "'"); - return false; + if (protocol) { + if (protocol.split(",").indexOf(header["sec-websocket-protocol"]) >= 0) { + protocol = header["sec-websocket-protocol"]; + } else { + onError("protocol doesn't match: '" + + header["websocket-protocol"] + "' not in '" + protocol + "'"); + return false; + } } return true; } diff --git a/flash-src/WebSocketMain.as b/flash-src/WebSocketMain.as index 5661df0..12d3329 100644 --- a/flash-src/WebSocketMain.as +++ b/flash-src/WebSocketMain.as @@ -70,6 +70,7 @@ public class WebSocketMain extends Sprite implements IWebSocketLogger{ eventObj.type = event.type; eventObj.webSocketId = webSocket.getId(); eventObj.readyState = webSocket.getReadyState(); + eventObj.protocol = webSocket.getProtocol(); if (event.message !== null) { eventObj.message = event.message; } diff --git a/web_socket.js b/web_socket.js index ec2a8b7..d080c6e 100644 --- a/web_socket.js +++ b/web_socket.js @@ -142,6 +142,9 @@ if ("readyState" in flashEvent) { this.readyState = flashEvent.readyState; } + if ("protocol" in flashEvent) { + this.protocol = flashEvent.protocol; + } var jsEvent; if (flashEvent.type == "open" || flashEvent.type == "error") { |