fix: be defensive around use of window.WebSocket#24
fix: be defensive around use of window.WebSocket#24keithamus wants to merge 1 commit intoappuri:masterfrom
Conversation
| new Error('An attempt was made to use a WebSocket that is not usable'), | ||
| { name: 'InvalidStateError' } | ||
| ) | ||
| } |
There was a problem hiding this comment.
Why would we try to re-implement the WebSocket standard? calling realWs.send.apply(...) should just throw this error.
There was a problem hiding this comment.
As previously stated - realWs.send is not always present
There was a problem hiding this comment.
But that's not what this code is checking. If you want to check for th3 existence of send and throw an Error, that is acceptible.
| } | ||
| })(function(global, navigator) { | ||
|
|
||
| var WebSocket = global.WebSocket |
There was a problem hiding this comment.
This doesn't make sense. either a) WebSocket is native and supported and never replaced, or b) it is polyfilled and we shouldn't close over and force the users to understand ordering of this library and the polyfill.
There was a problem hiding this comment.
The reason for this change is for another option: WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.
| } | ||
| Object.defineProperty(RobustWebSocket, name, descriptor) | ||
| Object.defineProperty(RobustWebSocket.prototype, name, descriptor) | ||
| }) |
There was a problem hiding this comment.
I'd be glad to take this change at robust-websocket's new home, nathanboktae/robust-websocket
|
Closing this one in favour of nathanboktae/robust-websocket#2 |
This fixes #19, #23 by being more defensive around the use of
window.WebSocket.It also provides more informational errors when attempting to call
.send()on a WebSocket that is notOPEN.