Skip to content

Commit

Permalink
add readyState constants to browser w3cwebsocket
Browse files Browse the repository at this point in the history
Now the exposed `w3cwebsocket` export mirrors the native WebSocket more closely.
I hit this bug when moving previously native code to use this wrapper, the server-sde code was fine,
but the client-side code failed because `WebSocket.OPEN` was `undefined`.
  • Loading branch information
thechriswalker committed May 22, 2017
1 parent 48468fc commit b27ba5e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ function W3CWebSocket(uri, protocols) {
*/
return native_instance;
}

if (NativeWebSocket) {
["CONNECTING", "OPEN", "CLOSING", "CLOSED"].forEach(function(prop) {
Object.defineProperty(W3CWebSocket, prop, {
get: function() { return NativeWebSocket[prop]; }
});
});
}

/**
* Module exports.
Expand Down

0 comments on commit b27ba5e

Please sign in to comment.