Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The WebSocket protocol property is not always a string #379

Open
rajsite opened this issue Jan 8, 2020 · 0 comments
Open

The WebSocket protocol property is not always a string #379

rajsite opened this issue Jan 8, 2020 · 0 comments

Comments

@rajsite
Copy link

rajsite commented Jan 8, 2020

The protocol property of the W3CWebSocket object returns undefined in some cases while browsers will return empty string instead.

From the spec, I don't think we should ever expect the protocol property to return undefined. Ie the protocol value is empty string unless the server replies with a non-null subprotocol value and then the value is updated to a new string.

I ran into this trying to re-use some browser JS code in node.js and had to create the following shim to prevent errors:

    const W3CWebSocket = require('websocket').w3cwebsocket;
    class WebSocketShim extends W3CWebSocket {
        get protocol () {
            return this._protocol === undefined ? '' : this._protocol;
        }
    }
rajsite added a commit to rajsite/webvi-experiments that referenced this issue Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant