mirror of
				https://github.com/JKorf/CryptoExchange.Net
				synced 2025-10-28 00:48:40 +00:00 
			
		
		
		
	Added handling for websocket options not being supported when running on WebAssembly
This commit is contained in:
		
							parent
							
								
									1e5f19271b
								
							
						
					
					
						commit
						98dad4a8ed
					
				| @ -9,6 +9,7 @@ using System.IO; | |||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Net; | using System.Net; | ||||||
| using System.Net.WebSockets; | using System.Net.WebSockets; | ||||||
|  | using System.Runtime.InteropServices; | ||||||
| using System.Threading; | using System.Threading; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
| 
 | 
 | ||||||
| @ -156,13 +157,22 @@ namespace CryptoExchange.Net.Sockets | |||||||
|                 cookieContainer.Add(new Cookie(cookie.Key, cookie.Value)); |                 cookieContainer.Add(new Cookie(cookie.Key, cookie.Value)); | ||||||
| 
 | 
 | ||||||
|             var socket = new ClientWebSocket(); |             var socket = new ClientWebSocket(); | ||||||
|             socket.Options.Cookies = cookieContainer; |             try | ||||||
|             foreach (var header in Parameters.Headers) |             { | ||||||
|                 socket.Options.SetRequestHeader(header.Key, header.Value); |                 socket.Options.Cookies = cookieContainer; | ||||||
|             socket.Options.KeepAliveInterval = Parameters.KeepAliveInterval ?? TimeSpan.Zero; |                 foreach (var header in Parameters.Headers) | ||||||
|             socket.Options.SetBuffer(65536, 65536); // Setting it to anything bigger than 65536 throws an exception in .net framework |                     socket.Options.SetRequestHeader(header.Key, header.Value); | ||||||
|             if (Parameters.Proxy != null) |                 socket.Options.KeepAliveInterval = Parameters.KeepAliveInterval ?? TimeSpan.Zero; | ||||||
|                 SetProxy(Parameters.Proxy); |                 socket.Options.SetBuffer(65536, 65536); // Setting it to anything bigger than 65536 throws an exception in .net framework | ||||||
|  |                 if (Parameters.Proxy != null) | ||||||
|  |                     SetProxy(Parameters.Proxy); | ||||||
|  |             } | ||||||
|  |             catch (PlatformNotSupportedException) | ||||||
|  |             { | ||||||
|  |                 // Options are not supported on certain platforms (WebAssembly for instance) | ||||||
|  |                 // best we can do it try to connect without setting options. | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             return socket; |             return socket; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user