diff --git a/samples/SocketsSample/EndPoints/ChatEndPoint.cs b/samples/SocketsSample/EndPoints/ChatEndPoint.cs index fdf501eb91..6e5174a06f 100644 --- a/samples/SocketsSample/EndPoints/ChatEndPoint.cs +++ b/samples/SocketsSample/EndPoints/ChatEndPoint.cs @@ -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(); diff --git a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs index e045def467..3170af0be8 100644 --- a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs @@ -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); }