From b3df10b638f994ebe5b6a12dc8491ea44cb846df Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 11 Jan 2017 09:57:12 -0800 Subject: [PATCH] Use connections format --- samples/SocketsSample/Hubs/Chat.cs | 13 +++++++++---- samples/SocketsSample/wwwroot/hubs.html | 5 +++++ .../RedisHubLifetimeManager.cs | 2 +- .../DefaultHubLifetimeManager.cs | 2 +- src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/samples/SocketsSample/Hubs/Chat.cs b/samples/SocketsSample/Hubs/Chat.cs index 5fe72faeae..80b3d3b145 100644 --- a/samples/SocketsSample/Hubs/Chat.cs +++ b/samples/SocketsSample/Hubs/Chat.cs @@ -11,12 +11,12 @@ namespace SocketsSample.Hubs { public override async Task OnConnectedAsync() { - await Clients.All.InvokeAsync("Send", $"{Context.Connection.ConnectionId} joined"); + await Clients.All.InvokeAsync("Send", $"{Context.ConnectionId} joined"); } public override async Task OnDisconnectedAsync(Exception ex) { - await Clients.All.InvokeAsync("Send", $"{Context.Connection.ConnectionId} left"); + await Clients.All.InvokeAsync("Send", $"{Context.ConnectionId} left"); } public Task Send(string message) @@ -31,7 +31,7 @@ namespace SocketsSample.Hubs public async Task JoinGroup(string groupName) { - await Clients.Group(groupName).InvokeAsync("Send", $"{Context.Connection.ConnectionId} joined {groupName}"); + await Clients.Group(groupName).InvokeAsync("Send", $"{Context.ConnectionId} joined {groupName}"); await Groups.AddAsync(groupName); } @@ -40,7 +40,12 @@ namespace SocketsSample.Hubs { await Groups.RemoveAsync(groupName); - await Clients.Group(groupName).InvokeAsync("Send", $"{Context.Connection.ConnectionId} left {groupName}"); + await Clients.Group(groupName).InvokeAsync("Send", $"{Context.ConnectionId} left {groupName}"); + } + + public Task Echo(string message) + { + return Clients.Client(Context.ConnectionId).InvokeAsync("Send", $"{Context.ConnectionId}: {message}"); } } } diff --git a/samples/SocketsSample/wwwroot/hubs.html b/samples/SocketsSample/wwwroot/hubs.html index e640c2a7f9..50eb252d78 100644 --- a/samples/SocketsSample/wwwroot/hubs.html +++ b/samples/SocketsSample/wwwroot/hubs.html @@ -159,4 +159,9 @@ click('groupmsg', event => { invoke(connection, 'SendToGroup', groupName, message); }); +click('send', event => { + let data = getText('me'); + invoke(connection, 'Echo', data); +}); + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs index 44c6d24922..0c9aa4a2d9 100644 --- a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs @@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis private Task WriteAsync(Connection connection, byte[] data) { var buffer = ReadableBuffer.Create(data).Preserve(); - return connection.Transport.Output.WriteAsync(new Message(buffer, Format.Binary, endOfMessage: true)); + return connection.Transport.Output.WriteAsync(new Message(buffer, connection.Metadata.Format, endOfMessage: true)); } private class LoggerTextWriter : TextWriter diff --git a/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs index 91cb6e13e6..bb3e90d9d8 100644 --- a/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.SignalR var stream = new MemoryStream(); invocationAdapter.WriteMessageAsync(message, stream); var buffer = ReadableBuffer.Create(stream.ToArray()).Preserve(); - return connection.Transport.Output.WriteAsync(new Message(buffer, Format.Binary, endOfMessage: true)); + return connection.Transport.Output.WriteAsync(new Message(buffer, connection.Metadata.Format, endOfMessage: true)); } } } diff --git a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs index 28a52668be..329a3a3c2d 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs @@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.SignalR var buffer = ReadableBuffer.Create(outStream.ToArray()).Preserve(); if (await connection.Transport.Output.WaitToWriteAsync()) { - connection.Transport.Output.TryWrite(new Message(buffer, Format.Binary, endOfMessage: true)); + connection.Transport.Output.TryWrite(new Message(buffer, connection.Metadata.Format, endOfMessage: true)); } } }