joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.21k stars 968 forks source link

sleepOnBlur + sleepOnBlurTimeout #49

Closed r3wt closed 9 years ago

r3wt commented 9 years ago

@joewalnes

I added these methods. i haven't tested it yet but i'm about to. Comments/Suggestions welcomed

r3wt commented 9 years ago

hmm, apparently status code 1001 can't be set?

this needs alot of work haha, it only half ass works

r3wt commented 9 years ago

img

r3wt commented 9 years ago

todo: possibly add event emission for onblur/onfocus?

agalazis commented 9 years ago

Disregard my previous post I just realised that you are actually stopping reconnects on blur that might be usefull sorry and thanks for bringing it up.

r3wt commented 9 years ago

@agalazis this is about maximizing performance and efficiency at scale really. say you have 10,000 connected clients, and 5,000 of them are idle connections with the browser window out of focus. wouldn't it be optimal to just disconnect those people until they refocus the window? i think so. additionally, it offers benefits in a pub sub model. the client is not connected, so when the data comes into the websocket server and the client id is not foumd, you can know to instead cache this information until the client reconnects

agalazis commented 9 years ago

Yes I have misinterpreted the point of this commit until i read the code, sorry for that.(that's why I deleted my post replied that it was actually useful. Not sure if many people would use it though, maybe thinking how expensive a re-connection would be(in different cases) , but the inclusion of this feature heavily depends on the criteria of the maintainer who tries to keep the code maintainable while always expanding to only new-important features - I am not a maintainer of this repository so my opinion doesn't matter much)

r3wt commented 9 years ago

@agalazis thats why the behavior is disabled by default

r3wt commented 9 years ago

This pull causes bugs in IE. i'm closing it.