@@ -19,6 +19,14 @@ internal class ClientWebSocketConnector : IWebSocketConnector
1919 private readonly ILoggerFactory _loggerFactory ;
2020 private readonly InvocatorRegistry _invocatorRegistry ;
2121
22+ public string ConnectionId
23+ {
24+ get
25+ {
26+ return _connectionId ;
27+ }
28+ }
29+
2230 public WebSocketState WebSocketState
2331 {
2432 get
@@ -40,26 +48,14 @@ public ClientWebSocketConnector(IOptions<ProxyOptions> options,
4048 Options = options . Value ;
4149 }
4250
43- private WebSocketMessageContext CreateConnectionContext ( )
44- {
45- var context = new WebSocketMessageContext ( ) ;
46- context . MessageType = WebSocketMessageType . Text ;
47- context . Command = WebSocketCommands . Connect ;
48- context . Header = new Dictionary < string , object >
49- {
50- [ "Name" ] = Options . ConnectorName
51- } ;
52-
53- return context ;
54- }
55-
5651 public async Task ConnectAsync ( )
5752 {
5853 try
5954 {
6055 var name = Options . ConnectorName ;
6156 var uri = new Uri ( $ "ws://{ Options . WebSocketHostAddress } ") ;
6257 _webSocket = new ClientWebSocket ( ) ;
58+ _webSocket . Options . SetRequestHeader ( SocketsConstants . ConnectorName , Options . ConnectorName ) ;
6359 await _webSocket . ConnectAsync ( uri , CancellationToken . None ) ;
6460 var receiverContext = new WebSocketReceiverContext
6561 {
@@ -69,7 +65,9 @@ public async Task ConnectAsync()
6965 Options = Options ,
7066 WebSocket = _webSocket
7167 } ;
72- var receiver = new WebSocketReceiver ( receiverContext , Close ) ;
68+ var receiver = new WebSocketReceiver ( receiverContext , Close , ( connectionId ) => {
69+ _connectionId = connectionId ;
70+ } ) ;
7371 await receiver . ReceiveAsync ( ) ;
7472 }
7573 catch ( Exception ex )
0 commit comments