Browser websocket fallback and support

Problem

Simple question: I saw on the site of socket.io several fallbacks for websockets (http://socket.io/#browser-support)

But I can not find (even after a long google session) which browsers use which fallback. The reason I'm asking is that I want to avoid a long polling fallback so I need to know which browsers and versions would use that.

[EDIT ]Seeing as this got downvoted I need to carify myself:

I need to know which browsers/versions eventually fall back to long polling. I can not simple assume the use of long polling in my case because long polling would present problems. Hope this makes it more clear and why I could not find it as easily..

[EDIT 2] Sorry for being so unclear:

I kinda see now that I basically asked which browsers use a fallback. But that's not what I meant to ask as I already know this. I meant to ask how to detect or know which fallback will be used. For my application flash is no problem, but long polling could present problems. Thanks!

Problem courtesy of: jansmolders86

Solution

If you want to know which browers work ahead of time, then Can I Use is a great reference.

If you want to detect support in your application when it is running, then you can just test for the existence of the WebSocket object:

if (WebSocket) {
    // Use websockets
} else {
    // Fallback will be used
}

(This code should be run on the client side, in the browser - not in your node.js app itself)

Edit:

If you need to know exactly what fallback is being used, create a socket, then check the socket.transport.name property. (So if your socket is called "socket", you'll be checking socket.socket.transport.name). It can be one of the following:

  • websocket
  • htmlfile
  • xhr-polling
  • jsonp-polling
Solution courtesy of: andypaxo

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.