I noticed on Firefox 6 (possibly other browsers) that the scope of event callbacks is inconsistent with Webkit's Websocket implementation. Websocket in Webkit will call event callbacks within the scope of the Websocket object. In Firefox 6, it is in the scope of the Window.
Here's a patch that addresses the issue, and it works for me:
diff --git a/web_socket.js b/web_socket.js
index 947a637..d62e0b6 100644
@@ -149,7 +149,7 @@
var handler = this["on" + event.type];
if (handler) handler.apply(this, [event]);
This would probably be a good thing to file as a bug with Mozilla too (if you haven't already). They may just not have thought about it and it would be good to get things consistent everywhere (and being called with this set to the WebSocket object makes the most sense).
Fixing scope of event callbacks (Bug #91 ).
Thanks for the report and patch. Pulled at:
@kanaka I confirmed that MozWebSocket in Firefox 6 does correct scope handling. I guess @alebsack only mentioned about Firefox 6 + web-socket-js.