summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <jmartin@sentryds.com>2011-05-02 17:30:38 -0500
committerHiroshi Ichikawa <gimite@gmail.com>2011-05-06 13:02:08 +0900
commitc1bde783368d575d789219dc40cddf3671307ae7 (patch)
treecff502b3790579fe68d32e8dadaa033471961cb6
parent4ddca99105555ab6b4ed41548eeca1a28a2f4f16 (diff)
downloadweb-socket-js-c1bde783368d575d789219dc40cddf3671307ae7.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.as16
-rw-r--r--flash-src/WebSocketMain.as1
-rw-r--r--web_socket.js3
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") {