laravel / echo

Laravel Echo library for beautiful Pusher and Ably integration.
https://laravel.com/docs/broadcasting#client-side-installation
MIT License
1.18k stars 182 forks source link

Leave channel and disconnect right after #393

Closed vatsake closed 7 months ago

vatsake commented 7 months ago

Echo Version

1.16

Laravel Version

11

PHP Version

8.2

NPM Version

9.7.1

Database Driver & Version

No response

Description

I'm trying to create a websocket service class in Angular.

I would like to disconnect from server if "no one" is currently listening to any events. If I send a "unlisten" request and then disconnect, browser will throw an error.

Steps To Reproduce

const echo = new Echo({
      authEndpoint: '...,
      broadcaster: 'reverb',
      key: '...',
      wsHost: 'localhost',
      wsPort: '8080',
      wssPort: '8080',
      forceTLS: true,
      enabledTransports: ['ws', 'wss'],
})

echo.listen('...', '...', () => {});

setTimeout(() => {
      echo.leave(...) <- this message will not be sent.
      echo.disconnect()
}, 2000)

Browser throws error: WebSocket is already in CLOSING or CLOSED state.

driesvints commented 7 months ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.