Fix be defensive around use of window websocket#2
Fix be defensive around use of window websocket#2keithamus wants to merge 2 commits intonathanboktae:masterfrom
Conversation
Allow attaching to connenctivity events to be disabled.
| } | ||
| })(function(global, navigator) { | ||
|
|
||
| var WebSocket = global.WebSocket |
There was a problem hiding this comment.
As per appuri/robust-websocket#24 (comment)
The reason for this change is: WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.
There was a problem hiding this comment.
WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.
But this can make it worse. Based on the load order (which is determined by what?) RobustWebSocket could close over the extention's implentation, or the native implementation. In the current usage, with lazy invocation, the user's code has more time and control to inject a different implementation.
| } | ||
| })(function(global, navigator) { | ||
|
|
||
| var WebSocket = global.WebSocket |
There was a problem hiding this comment.
WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.
But this can make it worse. Based on the load order (which is determined by what?) RobustWebSocket could close over the extention's implentation, or the native implementation. In the current usage, with lazy invocation, the user's code has more time and control to inject a different implementation.
|
|
||
| self.open = function() { | ||
| if (realWs.readyState !== WebSocket.OPEN && realWs.readyState !== WebSocket.CONNECTING) { | ||
| if (realWs.readyState !== self.OPEN && realWs.readyState !== self.CONNECTING) { |
There was a problem hiding this comment.
We don't and should not need to reimplement logic that is in the underlying WebSocket.prototype.send method. if it's missing, that's another thing and in that case, throwing an Error indicating it's missing is the most explicit, best experience for the user.
See the discussion up until now at appuri/robust-websocket#24