Skip to content

Commit 9d4dcc5

Browse files
gedemgedem
authored andcommitted
GetConnectionId extension method added
1 parent 3da6c00 commit 9d4dcc5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/NetCoreStack.WebSockets.ProxyClient/ClientWebSocketConnector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using NetCoreStack.WebSockets.Interfaces;
44
using NetCoreStack.WebSockets.Internal;
55
using System;
6-
using System.Collections.Generic;
76
using System.Linq;
87
using System.Net.WebSockets;
98
using System.Threading;

src/NetCoreStack.WebSockets/Extensions/WebSocketExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,21 @@ public static ArraySegment<byte> ToSegment(this WebSocketMessageContext webSocke
106106
var content = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(webSocketContext));
107107
return new ArraySegment<byte>(content, 0, content.Length);
108108
}
109+
110+
public static string GetConnectionId(this WebSocketMessageContext webSocketContext)
111+
{
112+
if (webSocketContext == null)
113+
{
114+
throw new ArgumentNullException(nameof(webSocketContext));
115+
}
116+
117+
object connectionId = null;
118+
if (webSocketContext.Header.TryGetValue(SocketsConstants.ConnectionId, out connectionId))
119+
{
120+
return connectionId.ToString();
121+
}
122+
123+
throw new ArgumentOutOfRangeException(nameof(connectionId));
124+
}
109125
}
110126
}

test/ServerTestApp/ServerWebSocketCommandInvocator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ public ServerWebSocketCommandInvocator(IConnectionManager connectionManager)
1313

1414
public async Task InvokeAsync(WebSocketMessageContext context)
1515
{
16-
if (context.Command == WebSocketCommands.Connect)
17-
{
18-
19-
}
16+
var connection = context.GetConnectionId();
2017

2118
// Sending incoming data from Backend zone to the Clients (Browsers)
2219
await _connectionManager.BroadcastAsync(context);

0 commit comments

Comments
 (0)