Use connections format

This commit is contained in:
BrennanConroy 2017-01-11 09:57:12 -08:00
parent cd9ed9228a
commit b3df10b638
5 changed files with 17 additions and 7 deletions

View File

@ -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}");
}
}
}

View File

@ -159,4 +159,9 @@ click('groupmsg', event => {
invoke(connection, 'SendToGroup', groupName, message);
});
click('send', event => {
let data = getText('me');
invoke(connection, 'Echo', data);
});
</script>

View File

@ -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

View File

@ -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));
}
}
}

View File

@ -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));
}
}
}