Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AutoTransport which is will pick the best transport supported b…
…y the client and server. - Added ConnectTimeout to ServerSentEventsTransport. - Handle stopping the SSE transport better. - Added Wp7 sample. - Added Delay event based on threading timers to the TaskAsyncHelper.
- Loading branch information
Showing
10 changed files
with
205 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace SignalR.Client.Transports | ||
{ | ||
public class AutoTransport : IClientTransport | ||
{ | ||
// Transport that's in use | ||
private IClientTransport _transport; | ||
|
||
// List of transports in fallback order | ||
private static readonly IClientTransport[] _transports = new[] { Transport.ServerSentEvents, Transport.LongPolling }; | ||
|
||
public Task Start(Connection connection, string data) | ||
{ | ||
var tcs = new TaskCompletionSource<object>(); | ||
|
||
// Resolve the transport | ||
ResolveTransport(connection, data, tcs, 0); | ||
|
||
return tcs.Task; | ||
} | ||
|
||
private void ResolveTransport(Connection connection, string data, TaskCompletionSource<object> tcs, int index) | ||
{ | ||
// Pick the current transport | ||
IClientTransport transport = _transports[index]; | ||
|
||
transport.Start(connection, data).ContinueWith(task => | ||
{ | ||
if (task.IsFaulted) | ||
{ | ||
// If that transport fails to initialize then fallback | ||
var next = index + 1; | ||
if (next < _transports.Length) | ||
{ | ||
// Try the next transport | ||
ResolveTransport(connection, data, tcs, next); | ||
} | ||
else | ||
{ | ||
// If there's nothing else to try then just fail | ||
tcs.SetException(task.Exception); | ||
} | ||
} | ||
else | ||
{ | ||
// Set the active transport | ||
_transport = transport; | ||
// Complete the process | ||
tcs.SetResult(null); | ||
} | ||
}); | ||
} | ||
|
||
public Task<T> Send<T>(Connection connection, string data) | ||
{ | ||
return _transport.Send<T>(connection, data); | ||
} | ||
|
||
public void Stop(Connection connection) | ||
{ | ||
_transport.Stop(connection); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters