pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.23k stars 199 forks source link

feat: make protocols updatable #132

Open XadillaX opened 4 years ago

XadillaX commented 4 years ago

In my scene, protocol should be updatable too. So this feature is inspired from UrlProvider.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.3%) to 94.581% when pulling d00224cc58dc54c32c9ffefee8633279617cf7b1 on XadillaX:protocols-provider into 05a2f7cb0e31f15dff5ff35ad53d07b1bec5e197 on pladaria:master.

XadillaX commented 4 years ago

/ping @pladaria

XadillaX commented 4 years ago

/ping @pladaria

bj00rn commented 3 years ago

@pladaria @XadillaX can we get this merged?

Having Protocols updatable would be awesome. A strong (but hackish) use case for this is sending JWT token securely when establishing connection, since the this is the only header available in the websocket browder implementation

Phil1216 commented 1 year ago

I was this close to coding up this feature myself. I too am using protocols for sending tokens.

bj00rn commented 1 year ago

Sad to see this library abandoned..

Partykit looks promising!

Here is a naive workaround i was using..

export default class Socket extends ReconnectingWebSocket {
    constructor(urlProvider, protocolsProvider) {
        /**
         * Workaround to authenticate websocket over Sec-Websocket-Protocol header
         * see issue at (https://github.com/whatwg/websockets/issues/16)
         * @class _WebSocket
         * @extends {WebSocket}
         */
        class _WebSocket extends WebSocket {
            constructor(url) {
                super(url, protocolsProvider())
            }
        }

        super(urlProvider, undefined, {
            WebSocket: _WebSocket,
        })
    }
}