Use connections format
This commit is contained in:
parent
cd9ed9228a
commit
b3df10b638
|
|
@ -11,12 +11,12 @@ namespace SocketsSample.Hubs
|
||||||
{
|
{
|
||||||
public override async Task OnConnectedAsync()
|
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)
|
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)
|
public Task Send(string message)
|
||||||
|
|
@ -31,7 +31,7 @@ namespace SocketsSample.Hubs
|
||||||
|
|
||||||
public async Task JoinGroup(string groupName)
|
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);
|
await Groups.AddAsync(groupName);
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,12 @@ namespace SocketsSample.Hubs
|
||||||
{
|
{
|
||||||
await Groups.RemoveAsync(groupName);
|
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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,4 +159,9 @@ click('groupmsg', event => {
|
||||||
invoke(connection, 'SendToGroup', groupName, message);
|
invoke(connection, 'SendToGroup', groupName, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
click('send', event => {
|
||||||
|
let data = getText('me');
|
||||||
|
invoke(connection, 'Echo', data);
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
private Task WriteAsync(Connection connection, byte[] data)
|
private Task WriteAsync(Connection connection, byte[] data)
|
||||||
{
|
{
|
||||||
var buffer = ReadableBuffer.Create(data).Preserve();
|
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
|
private class LoggerTextWriter : TextWriter
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
invocationAdapter.WriteMessageAsync(message, stream);
|
invocationAdapter.WriteMessageAsync(message, stream);
|
||||||
var buffer = ReadableBuffer.Create(stream.ToArray()).Preserve();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
var buffer = ReadableBuffer.Create(outStream.ToArray()).Preserve();
|
var buffer = ReadableBuffer.Create(outStream.ToArray()).Preserve();
|
||||||
if (await connection.Transport.Output.WaitToWriteAsync())
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue