Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment to version 2.2.2 of SignalR #1

Open
wants to merge 5 commits into
base: feature/websocketssharp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/v2.x/HubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,26 @@ private static string GetUrl(string url, bool useDefaultUrl)

private void ClearInvocationCallbacks(string error)
{
var result = new HubResult();
result.Error = error;

lock (_callbacks)
{
foreach (var callback in _callbacks.Values)
{
callback(result);
}

_callbacks.Clear();
}
}
Action<HubResult>[] callbacks;

lock (_callbacks)
{
callbacks = _callbacks.Values.ToArray();
_callbacks.Clear();
}

foreach (var callback in callbacks)
{
// Create a new HubResult each time as it's mutable and we don't want callbacks
// changing it during their parallel invocation
Task.Factory.StartNew(() => callback(new HubResult { Error = error }))
.Catch();
}
}

public void Force()
{
ClearInvocationCallbacks("Force");
}
}
}
3 changes: 2 additions & 1 deletion src/v2.x/Hubs/HubRegistrationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Microsoft.AspNet.SignalR.Client.Hubs
{
public class HubRegistrationData
{
public string Name { get; set; }
[Newtonsoft.Json.JsonProperty(PropertyName = "name")]
public string Name { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/v2.x/Infrastructure/TransportAbortHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Abort(IConnection connection, TimeSpan timeout, string connectionDat
string url = connection.Url + "abort" + String.Format(CultureInfo.InvariantCulture,
_abortQueryString,
_transportName,
connectionData,
Uri.EscapeDataString(connectionData),
Uri.EscapeDataString(connection.ConnectionToken),
null);

Expand Down
3 changes: 3 additions & 0 deletions src/v2.x/Nivot.SignalR.Client.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Rackspace.Threading, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d693b28384d1c375, processorArchitecture=MSIL">
<HintPath>..\packages\TunnelVisionLabs.Threading.2.0.0\lib\net35-client\Rackspace.Threading.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Threading">
Expand Down
2 changes: 1 addition & 1 deletion src/v2.x/Transports/HttpBasedTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Task Send(IConnection connection, string data, string connectionData)
url += String.Format(CultureInfo.InvariantCulture,
_sendQueryString,
_transport,
connectionData,
Uri.EscapeDataString(connectionData),
Uri.EscapeDataString(connection.ConnectionToken),
customQueryString);

Expand Down
4 changes: 4 additions & 0 deletions src/v2.x/Transports/ServerSentEventsTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ private void OpenConnection(IConnection connection,
// Raise the reconnect event if the connection comes back up
connection.OnReconnected();
}
else
{
connection.ChangeState(ConnectionState.Disconnected, ConnectionState.Connected);
}
};

eventSource.Message = sseEvent =>
Expand Down
4 changes: 2 additions & 2 deletions src/v2.x/Transports/TransportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Task<NegotiationResponse> GetNegotiationResponse(this IHttpClient

if (!String.IsNullOrEmpty(connectionData))
{
negotiateUrl += "&connectionData=" + connectionData;
negotiateUrl += "&connectionData=" + Uri.EscapeDataString(connectionData);
}

httpClient.Initialize(connection);
Expand Down Expand Up @@ -85,7 +85,7 @@ public static string GetReceiveQueryString(IConnection connection, string connec

if (connectionData != null)
{
qsBuilder.Append("&connectionData=" + connectionData);
qsBuilder.Append("&connectionData=" + Uri.EscapeDataString(connectionData));
}

qsBuilder.Append("&clientProtocol=" + connection.Protocol);
Expand Down
11 changes: 6 additions & 5 deletions src/v2.x/Transports/WebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,20 @@ public virtual Task PerformConnect() {

private async Task PerformConnect(bool reconnecting) {
var url = _connectionInfo.Connection.Url + (reconnecting ? "reconnect" : "connect");
url += TransportHelper.GetReceiveQueryString(_connectionInfo.Connection, _connectionInfo.Data, "webSockets");
var builder = new UriBuilder(url);
var qs = TransportHelper.GetReceiveQueryString(_connectionInfo.Connection, _connectionInfo.Data, "webSockets");
qs += "&tid=" + new Random((int)DateTime.Now.Ticks).Next();
var builder = new UriBuilder(url);
builder.Scheme = builder.Scheme == "https" ? "wss" : "ws";

_connectionInfo.Connection.Trace(TraceLevels.Events, "WS Connecting to: {0}", builder.Uri);
_connectionInfo.Connection.Trace(TraceLevels.Events, "WS Connecting to: {0}", builder.Uri+qs);

// TODO: Revisit thread safety of this assignment
_webSocketTokenSource = new CancellationTokenSource();

CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_webSocketTokenSource.Token, _disconnectToken);
CancellationToken token = linkedCts.Token;

_webSocket = new ClientWebSocket(builder.Uri.ToString(), token, null);
_webSocket = new ClientWebSocket(builder.Uri.ToString()+qs, token, null);

_webSocket.Log = new Logger(LogLevel.Trace, null, ((data, s) => _connectionInfo.Connection.Trace(TraceLevels.All, "WebSocket - {0}", data.Message)));
_webSocket.OnOpen += (sender, args) => _connectionInfo.Connection.ChangeState(_connectionInfo.Connection.State, ConnectionState.Connected);
Expand Down Expand Up @@ -139,7 +140,7 @@ public Task Send(IConnection connection, string data, string connectionData) {
return TaskAsyncHelper.FromError(ex);
}

return SendAsync(data);
return SendAsync(connection,data);
}

public override void OnMessage(string message) {
Expand Down
2 changes: 1 addition & 1 deletion src/v2.x/Transports/WebSockets/WebSocketMessageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ await TaskEx.Run(() => {
public static async Task<WebSocketMessage> ReadMessageAsync(WebSocket webSocket, int bufferSize,
int? maxMessageSize, CancellationToken disconnectToken) {
WebSocketReceiveResult receiveResult = await WSRecieveAsync(webSocket, disconnectToken).ConfigureAwait(false);
if(receiveResult.MessageType == WebSocketMessageType.Close)
if(receiveResult == null || receiveResult.MessageType == WebSocketMessageType.Close)
return WebSocketMessage.CloseMessage;
return new WebSocketMessage(receiveResult.Message, receiveResult.MessageType);
}
Expand Down
8 changes: 4 additions & 4 deletions src/v2.x/WebSockets/DefaultWebSocketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ Action<Exception> IWebSocket.OnError {
set;
}

Task IWebSocket.Send(string value) {
return Send(value);
Task IWebSocket.Send(IConnection connection, string value) {
return Send(connection, value);
}

public override Task Send(string message) {
public override Task Send(IConnection connection ,string message) {
if (_closed) {
return TaskAsyncHelper.Empty;
}

return base.Send(message);
return base.Send(connection,message);
}

public override Task CloseAsync() {
Expand Down
3 changes: 2 additions & 1 deletion src/v2.x/WebSockets/IWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ internal interface IWebSocket
/// <summary>
/// Sends data over the websocket.
/// </summary>
/// <param name="connection"></param>
/// <param name="value">The value to send.</param>
/// <returns>A <see cref="Task"/> that represents the send is complete.</returns>
Task Send(string value);
Task Send(IConnection connection, string value);

/// <summary>
/// Sends a chunk of data over the websocket ("endOfMessage" flag set to false.)
Expand Down
Loading