ricardomatias / ableton-live

A library for communicating with Live via WebSockets, works both in NodeJS and in the Browser.
https://ricardomatias.net/ableton-live/
79 stars 10 forks source link

Send close frame to clients when server is closed #9

Closed giohappy closed 1 year ago

giohappy commented 2 years ago

I want my client to be notified when the server is closed (port changed). I was able to get the expected message by calling ws.end() on each client after this line:

maxApi.addHandler('port', async (port) => {
    try {
        if (uws) {
            console.log('Attempting to close server..');

            if (listenSocket) uWS.us_listen_socket_close(listenSocket);

            SOCKETS.forEach((ws, i) => ws.end());
        }

        console.log('Creating server..');

        ....

As uWebSockets explains, ws.end() does:

Send websocket close frame, emit close event, send FIN if successful. Will not append a close reason if code is 0 or 1005.

ricardomatias commented 2 years ago

Good find! I've added this to my wip branch, so if you don't wish to create a PR, it will eventually be merged onto master.

giohappy commented 2 years ago

I can wait for the merge of the wip branch. Do you know more or less when it will happen?

ricardomatias commented 1 year ago

Sorry for the long delay @giohappy. There have been a few updates to the project this past week and I'm now returning to this issue. Did you get to try the "wip" branch?

giohappy commented 1 year ago

@ricardomatias unfortunately I hade to pause my side project where I was using your code. I hope I will be back on it sooner then later, but there"s a good chance it will be with a Python client.

ricardomatias commented 1 year ago

Part of the latest release of v0.0.10