Add transport connection metadata

This commit is contained in:
David Fowler 2016-10-01 23:49:07 -07:00
parent 58d08c07d0
commit 9ee33bf01f
2 changed files with 6 additions and 2 deletions

View File

@ -16,7 +16,7 @@ namespace SocketsSample
{ {
await bus.Publish(nameof(ChatEndPoint), new Message await bus.Publish(nameof(ChatEndPoint), new Message
{ {
Payload = Encoding.UTF8.GetBytes($"{connection.ConnectionId} connected") Payload = Encoding.UTF8.GetBytes($"{connection.ConnectionId} connected ({connection.Metadata["transport"]})")
}); });
using (bus.Subscribe(nameof(ChatEndPoint), message => OnMessage(message, connection))) using (bus.Subscribe(nameof(ChatEndPoint), message => OnMessage(message, connection)))
@ -45,7 +45,7 @@ namespace SocketsSample
await bus.Publish(nameof(ChatEndPoint), new Message await bus.Publish(nameof(ChatEndPoint), new Message
{ {
Payload = Encoding.UTF8.GetBytes($"{connection.ConnectionId} disconnected") Payload = Encoding.UTF8.GetBytes($"{connection.ConnectionId} disconnected ({connection.Metadata["transport"]})")
}); });
connection.Channel.Input.Complete(); connection.Channel.Input.Complete();

View File

@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Sockets
{ {
// Get the connection state for the current http context // Get the connection state for the current http context
var connectionState = GetOrCreateConnection(context); var connectionState = GetOrCreateConnection(context);
connectionState.Connection.Metadata["transport"] = "sse";
var sse = new ServerSentEvents(connectionState.Connection); var sse = new ServerSentEvents(connectionState.Connection);
// Register this transport for disconnect // Register this transport for disconnect
@ -75,6 +76,7 @@ namespace Microsoft.AspNetCore.Sockets
{ {
// Get the connection state for the current http context // Get the connection state for the current http context
var connectionState = GetOrCreateConnection(context); var connectionState = GetOrCreateConnection(context);
connectionState.Connection.Metadata["transport"] = "websockets";
var ws = new WebSockets(connectionState.Connection); var ws = new WebSockets(connectionState.Connection);
// Register this transport for disconnect // Register this transport for disconnect
@ -122,6 +124,8 @@ namespace Microsoft.AspNetCore.Sockets
// Raise OnConnected for new connections only since polls happen all the time // Raise OnConnected for new connections only since polls happen all the time
if (isNewConnection) if (isNewConnection)
{ {
connectionState.Connection.Metadata["transport"] = "poll";
// REVIEW: We should await this task after disposing the connection // REVIEW: We should await this task after disposing the connection
var ignore = endpoint.OnConnected(connectionState.Connection); var ignore = endpoint.OnConnected(connectionState.Connection);
} }