3 ms·
Relying on feature detection alone for WebSocket is a big mistake though. Websocket can fail for a number of reasons - proxies, stupid ISPs that interfere with
by axod 16y ago
Relying on feature detection alone for WebSocket is a big mistake though. Websocket can fail for a number of reasons - proxies, stupid ISPs that interfere with HTTP traffic etc.
In Mibbit, the code is something like this:
if(WebSocket in window) {
tryWebsocket();
window.setTimeout(function() {
if (nothingHappened()) useComet()
}, 5*1000);
} else {
useComet();
}
Where comet in this case is keep alive long polling XHR.
- taitems 16y agoThat's an interesting way of managing timeouts. Is the 5*1000 intended to just be a more readable way of specifying seconds?
- catechu 16y agoHow can you check if nothing happened?
- jacquesm 16y agoBy changing some global variable in the callback and checking if it has changed in 'somethinghappened' (which only gets called after 5 seconds, giving the callback time enough to get called).
- bradgessler 16y agoLibraries like Socket.IO will detect if the connection can be made or not... so this point is moot. Feature detection first, connection detection second, then start degrading the transport until all options are exhausted.
- axod 16y agoSure. I was just explaining for those who prefer to write things like this themselves.