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

Custom ReasonCode not passed in closeEvent #420

Open
hazaart opened this issue Jul 5, 2021 · 5 comments
Open

Custom ReasonCode not passed in closeEvent #420

hazaart opened this issue Jul 5, 2021 · 5 comments

Comments

@hazaart
Copy link

hazaart commented Jul 5, 2021

The spec for websocket provides a range for custom reason codes to be sent when closing the websocket (4000-4999). When closing a websocket connection from the client passing a custom reason code, the code is not received within the onclose event.

Code on websocketServer:

    this._httpServer = createServer();
    this._httpServer.listen(port, () => { });
    this._websocketServer = new websocketServer({ httpServer: this._httpServer });

    console.log(`Websocket server now listenening on port ${port}`);

    this._websocketServer.on('request',
        (request) => {
            const connection = request.accept(undefined, request.origin);

            connection.on('message', function (message) {
                //DoSomething
            });
        }
    );

Code on client side: See JSFiddle https://jsfiddle.net/254megph/2/

websocket.close(4000, "manual close");

When closing the connection by clicking the button the JSFiddle, the onClose event is fired with reason code 1000 instead of 4000.

@formula1
Copy link

formula1 commented Feb 25, 2022

It seems as though it always sends a close normal code so long as it's valid

Do you know off hand if it should always return what it received? This could be a relatively easy fix but I don't want to go against the spec.

@avoliva
Copy link

avoliva commented Apr 20, 2022

It seems as though it always sends a close normal code so long as it's valid

What's the point in providing a code then?

@avoliva
Copy link

avoliva commented Apr 21, 2022

When using the JS WebSocket implementation and providing a code and reason, the WebSocket closes with that code and reason in the close event. This doesn't appear to be the case in this library

@formula1
Copy link

this project might be dead

@rgillan
Copy link

rgillan commented Nov 23, 2023

From memory I don't think there's been discussion about supporting custom codes over the history of this module. Pretty sure the code support is based upon the "required" parts of the spec:
https://kapeli.com/cheat_sheets/WebSocket_Status_Codes.docset/Contents/Resources/Documents/index

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

4 participants