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

Multiple Websocket connection ? #79

Open
cubecleveland opened this issue Apr 21, 2021 · 5 comments
Open

Multiple Websocket connection ? #79

cubecleveland opened this issue Apr 21, 2021 · 5 comments

Comments

@cubecleveland
Copy link

Hello,
Not sure if this is an issue or a discussion or just not understangin the code.. :)

Looked at the code and it seems like every component is opening a new WebSocket connection via new WebSocket()
I cant really spot the 'sharing mechanism' Can u assist ands let me know where in the code the compoenent actually shares the connection that akleady exist s?

Thanks
R

@robtaussig
Copy link
Owner

Hi @cubecleveland,

Are you passing { share: true } in the option param?

https://github.com/robtaussig/react-use-websocket#share-boolean

@cubecleveland
Copy link
Author

Hi!

Yes i solved it, i read through the code and i think the imlemetation is neat but the use case for me would not work in the way the socket was implemented and the share.

Mainly im looking for a function that will only update the socket every interval......
Only send the queeuu to the COmponeent every 10 seconds in an array of what was recieved in the last interval.

Reason is im dealing with 100's of events per seconds.
Can that be acheived uasing the filter param ?

@robtaussig
Copy link
Owner

@cubecleveland

I'm glad you brought that up -- I have been meaning to implement a throttle param that does just that -- accept a duration, and batch messages in groups such that you only ever get one update per interval. I think I'll do that next!

I think using the filter param is interesting and probably more performant than my next suggestion, but it will require abusing the filter callback:) alternatively, you can wrap useWebsocket with your own custom hook that batches the messages, but I'm struggling to imagine whether this would actually solve the performance problem of rapid updates since your component is already being updated by the internal hook.

@cubecleveland
Copy link
Author

Correct.

IMHO..... using the filter doesnt work and it will require some refactoring .
Maybe adding Interval params to the option and justrun the filter on that interval... just a thought....
either way will be a great thing....

In the meantime, i just implemented my owb hook not using your library but i would love to once this feature is enabled...

Thanks so much for your great work!

@krall12
Copy link

krall12 commented Mar 13, 2023

Not sure if related but is there a way to share connections between different paths on the same socket URL?

So imagine I had a /connect endpoint to establish the connection but also wanted to share it with a /file-upload endpoint on the same socket. Is that something that is possible?

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

3 participants