Allow option for disconnectSync timeout for browsers that support it #469
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[rant]Personally I have to use xhr-polling because websockets still have a rising memory usage until I run out of memory. [/rant]
When using xhr-polling I need to know when a visitor changes pages on the site so I use opts['sync disconnect on unload'] = true;
However, I've noticed that if the node server is having trouble keeping up or some network connection issue, then this unload function halts the browser (I think this is because the xhr request is sync, which it needs to be in order to reach the server).
I discovered that some browsers respect a timeout setting on an xhr object. So, this commit gives you a new option to set opts['sync disconnect timeout'] = 300; // ms
It defaults to 0, so it will have the same original behavior. Otherwise you can set a number in ms for the function to timeout if the server doesn't respond.