Add transport connection metadata
This commit is contained in:
parent
58d08c07d0
commit
9ee33bf01f
|
|
@ -16,7 +16,7 @@ namespace SocketsSample
|
|||
{
|
||||
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)))
|
||||
|
|
@ -45,7 +45,7 @@ namespace SocketsSample
|
|||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
{
|
||||
// Get the connection state for the current http context
|
||||
var connectionState = GetOrCreateConnection(context);
|
||||
connectionState.Connection.Metadata["transport"] = "sse";
|
||||
var sse = new ServerSentEvents(connectionState.Connection);
|
||||
|
||||
// Register this transport for disconnect
|
||||
|
|
@ -75,6 +76,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
{
|
||||
// Get the connection state for the current http context
|
||||
var connectionState = GetOrCreateConnection(context);
|
||||
connectionState.Connection.Metadata["transport"] = "websockets";
|
||||
var ws = new WebSockets(connectionState.Connection);
|
||||
|
||||
// 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
|
||||
if (isNewConnection)
|
||||
{
|
||||
connectionState.Connection.Metadata["transport"] = "poll";
|
||||
|
||||
// REVIEW: We should await this task after disposing the connection
|
||||
var ignore = endpoint.OnConnected(connectionState.Connection);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue