How does SignalR decide which transport method to

2019-02-12 06:18发布

问题:

SignalR is an abstraction over transports used for real-time connections. Still I'd like to know how exactly it decides which transport methods should be used, depending on various factors. I did some research using available documentation and looked into sources and came up with an idea how it works.

So my actual question would be, is the following flowchart correct or am I missing anything?

Update:

Thanks for your input! Here is an updated version according to your fixes. But I'm still not sure about one thing: if there is no explicit check whether IE9+ is used, what triggers the fallback from ForeverFrame to LP if it's not IE and does not support SSE?

回答1:

Awesome diagram first off.

It's very close! Here's some fixes:

Configured JSONP
 Yes -> Use LP  
 No -> IsCrossDomain  
       Yes -> CORS Support?  
              No -> JSONP = true  
                    -> Use LP  
              Yes -> Server Supports WebSockets  
                     Yes -> Client Supports WebSockets  
                            Yes -> Use WebSockets  
                            No -> Use LP  
                     No -> Use LP  
              No -> Use LP  

One other slight detail: ForeverFrame is always tried before SSE (even in Chrome) but within the transport itself it checks if EventSource (the underlying method of SSE) exists, if it exists then the forever frame fails to start (so that it can fall back to SSE). Therefore IE9+ is never a direct check.

With my fixes implemented your diagram would then be accurate.