|
15 | 15 | */ |
16 | 16 | namespace HiveMQtt.Client; |
17 | 17 |
|
| 18 | +using System; |
| 19 | +using System.Collections.Generic; |
| 20 | +using System.Net; |
18 | 21 | using System.Security; |
19 | 22 | using System.Security.Cryptography.X509Certificates; |
20 | 23 | using HiveMQtt.Client.Options; |
@@ -91,6 +94,81 @@ public HiveMQClientOptionsBuilder WithWebSocketServer(string webSocketServer) |
91 | 94 | return this; |
92 | 95 | } |
93 | 96 |
|
| 97 | + /// <summary> |
| 98 | + /// Sets the WebSocket keep-alive interval. |
| 99 | + /// <para> |
| 100 | + /// This specifies the interval at which the WebSocket client will send keep-alive pings to the server |
| 101 | + /// to maintain the connection. If not set, the default WebSocket keep-alive behavior is used. |
| 102 | + /// </para> |
| 103 | + /// <para> |
| 104 | + /// This option is only applicable when using WebSocket transport (ws:// or wss://). |
| 105 | + /// </para> |
| 106 | + /// </summary> |
| 107 | + /// <param name="keepAliveInterval">The keep-alive interval.</param> |
| 108 | + /// <returns>The HiveMQClientOptionsBuilder instance.</returns> |
| 109 | + public HiveMQClientOptionsBuilder WithWebSocketKeepAliveInterval(TimeSpan keepAliveInterval) |
| 110 | + { |
| 111 | + this.options.WebSocketKeepAliveInterval = keepAliveInterval; |
| 112 | + return this; |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Sets custom HTTP headers to be sent during the WebSocket handshake. |
| 117 | + /// <para> |
| 118 | + /// This allows you to add custom headers such as Authorization, X-API-Key, or any other |
| 119 | + /// custom headers required by your WebSocket server. Headers are sent during the initial WebSocket |
| 120 | + /// connection handshake. |
| 121 | + /// </para> |
| 122 | + /// <para> |
| 123 | + /// This option is only applicable when using WebSocket transport (ws:// or wss://). |
| 124 | + /// </para> |
| 125 | + /// </summary> |
| 126 | + /// <param name="headers">A dictionary of header names and values.</param> |
| 127 | + /// <returns>The HiveMQClientOptionsBuilder instance.</returns> |
| 128 | + public HiveMQClientOptionsBuilder WithWebSocketRequestHeaders(Dictionary<string, string> headers) |
| 129 | + { |
| 130 | + this.options.WebSocketRequestHeaders = headers; |
| 131 | + return this; |
| 132 | + } |
| 133 | + |
| 134 | + /// <summary> |
| 135 | + /// Adds a custom HTTP header to be sent during the WebSocket handshake. |
| 136 | + /// <para> |
| 137 | + /// This is a convenience method for adding a single header. For multiple headers, use |
| 138 | + /// <see cref="WithWebSocketRequestHeaders(Dictionary{string, string})"/>. |
| 139 | + /// </para> |
| 140 | + /// <para> |
| 141 | + /// This option is only applicable when using WebSocket transport (ws:// or wss://). |
| 142 | + /// </para> |
| 143 | + /// </summary> |
| 144 | + /// <param name="name">The header name.</param> |
| 145 | + /// <param name="value">The header value.</param> |
| 146 | + /// <returns>The HiveMQClientOptionsBuilder instance.</returns> |
| 147 | + public HiveMQClientOptionsBuilder WithWebSocketRequestHeader(string name, string value) |
| 148 | + { |
| 149 | + this.options.WebSocketRequestHeaders ??= new Dictionary<string, string>(); |
| 150 | + this.options.WebSocketRequestHeaders[name] = value; |
| 151 | + return this; |
| 152 | + } |
| 153 | + |
| 154 | + /// <summary> |
| 155 | + /// Sets the proxy configuration for WebSocket connections. |
| 156 | + /// <para> |
| 157 | + /// This allows you to configure a proxy server for WebSocket connections. If not set, the system's |
| 158 | + /// default proxy settings are used. |
| 159 | + /// </para> |
| 160 | + /// <para> |
| 161 | + /// This option is only applicable when using WebSocket transport (ws:// or wss://). |
| 162 | + /// </para> |
| 163 | + /// </summary> |
| 164 | + /// <param name="proxy">The proxy configuration.</param> |
| 165 | + /// <returns>The HiveMQClientOptionsBuilder instance.</returns> |
| 166 | + public HiveMQClientOptionsBuilder WithWebSocketProxy(IWebProxy proxy) |
| 167 | + { |
| 168 | + this.options.WebSocketProxy = proxy; |
| 169 | + return this; |
| 170 | + } |
| 171 | + |
94 | 172 | /// <summary> |
95 | 173 | /// Sets the port to connect to. |
96 | 174 | /// <para> |
|
0 commit comments