1- using SocketIOClient . JsonSerializer ;
2- using SocketIOClient . Messages ;
1+ using SocketIOClient . Messages ;
32using SocketIOClient . UriConverters ;
43using System ;
54using System . Collections . Generic ;
@@ -14,20 +13,20 @@ namespace SocketIOClient.Transport
1413{
1514 public class TransportRouter : IDisposable
1615 {
17- public TransportRouter ( HttpClient httpClient , Func < IClientWebSocket > clientWebSocketProvider )
16+ public TransportRouter ( HttpClient httpClient , Func < IClientWebSocket > clientWebSocketProvider , SocketIOOptions options )
1817 {
1918 _httpClient = httpClient ;
2019 _clientWebSocketProvider = clientWebSocketProvider ;
2120 UriConverter = new UriConverter ( ) ;
22- Path = "/socket.io" ;
23- ConnectionTimeout = TimeSpan . FromSeconds ( 20 ) ;
2421 _messageQueue = new Queue < IMessage > ( ) ;
22+ _options = options ;
2523 }
2624
2725 readonly HttpClient _httpClient ;
2826 IClientWebSocket _clientWebSocket ;
2927 readonly Queue < IMessage > _messageQueue ;
3028 readonly Func < IClientWebSocket > _clientWebSocketProvider ;
29+ readonly SocketIOOptions _options ;
3130
3231 HttpTransport _httpTransport ;
3332 WebSocketTransport _webSocketTransport ;
@@ -37,16 +36,8 @@ public TransportRouter(HttpClient httpClient, Func<IClientWebSocket> clientWebSo
3736
3837 public Uri ServerUri { get ; set ; }
3938
40- public string Path { get ; set ; }
41-
4239 public string Namespace { get ; set ; }
4340
44- public bool AutoUpgrade { get ; set ; }
45-
46- public IEnumerable < KeyValuePair < string , string > > QueryParams { get ; set ; }
47-
48- public TimeSpan ConnectionTimeout { get ; set ; }
49-
5041 public TransportProtocol Protocol { get ; private set ; }
5142
5243 public string Sid { get ; private set ; }
@@ -63,11 +54,11 @@ public async Task ConnectAsync()
6354 {
6455 _webSocketTransport . Dispose ( ) ;
6556 }
66- Uri uri = UriConverter . GetHandshakeUri ( ServerUri , Path , QueryParams ) ;
57+ Uri uri = UriConverter . GetHandshakeUri ( ServerUri , _options . Path , _options . Query ) ;
6758
6859 var req = new HttpRequestMessage ( HttpMethod . Get , uri ) ;
6960
70- var resMsg = await _httpClient . SendAsync ( req , new CancellationTokenSource ( ConnectionTimeout ) . Token ) . ConfigureAwait ( false ) ;
61+ var resMsg = await _httpClient . SendAsync ( req , new CancellationTokenSource ( _options . ConnectionTimeout ) . Token ) . ConfigureAwait ( false ) ;
7162 if ( ! resMsg . IsSuccessStatusCode )
7263 {
7364 throw new HttpRequestException ( $ "Response status code does not indicate success: { resMsg . StatusCode } ") ;
@@ -77,15 +68,15 @@ public async Task ConnectAsync()
7768 int index = text . IndexOf ( '{' ) ;
7869 string json = text . Substring ( index ) ;
7970
80- var doc = JsonDocument . Parse ( json ) . RootElement ;
71+ var doc = JsonDocument . Parse ( json ) . RootElement ;
8172 Sid = doc . GetProperty ( "sid" ) . GetString ( ) ;
8273 string upgrades = doc . GetProperty ( "upgrades" ) . GetRawText ( ) ;
83- if ( upgrades . Contains ( "websocket" ) && AutoUpgrade )
74+ if ( upgrades . Contains ( "websocket" ) && _options . AutoUpgrade )
8475 {
8576 _clientWebSocket = _clientWebSocketProvider ( ) ;
8677 _webSocketTransport = new WebSocketTransport ( _clientWebSocket )
8778 {
88- ConnectionTimeout = ConnectionTimeout
79+ ConnectionTimeout = _options . ConnectionTimeout
8980 } ;
9081 await WebSocketConnectAsync ( ) . ConfigureAwait ( false ) ;
9182 Protocol = TransportProtocol . WebSocket ;
@@ -101,7 +92,7 @@ public async Task ConnectAsync()
10192
10293 private async Task WebSocketConnectAsync ( )
10394 {
104- Uri uri = UriConverter . GetWebSocketUri ( ServerUri , Path , QueryParams , Sid ) ;
95+ Uri uri = UriConverter . GetWebSocketUri ( ServerUri , _options . Path , _options . Query , Sid ) ;
10596 await _webSocketTransport . ConnectAsync ( uri ) . ConfigureAwait ( false ) ;
10697 _webSocketTransport . OnTextReceived = OnWebSocketTextReceived ;
10798 _webSocketTransport . OnBinaryReceived = OnBinaryReceived ;
0 commit comments