You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/signalr/client-features.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,18 +29,18 @@ The 1.x versions of SignalR map to the 2.1 and 2.2 .NET Core releases and have t
29
29
30
30
The table below shows the features and support for the clients that offer real-time support. For each feature, the *minimum* version supporting this feature is listed. If no version is listed, the feature isn't supported.
@@ -175,6 +170,22 @@ let connection = HubConnectionBuilder()
175
170
176
171
Without parameters, withAutomaticReconnect() configures the client to wait 0, 2, 10, and 30 seconds respectively before each reconnect attempt. After four failed attempts, the client stops trying to reconnect.
177
172
173
+
Before starting any reconnect attempts, the `HubConnection` transitions to the `Reconnecting` state and fires its `onReconnecting` callbacks.
174
+
175
+
After the reconnection succeeds, the `HubConnection` transitions to the `connected` state and fires its `onReconnected` callbacks.
176
+
177
+
A general way to use `onReconnecting` and `onReconnected` is to mark the connection state changes:
178
+
179
+
```swift
180
+
connection.onReconnecting { error in
181
+
// connection is disconnected because of error
182
+
}
183
+
184
+
connection.onReconnected {
185
+
// connection is connected back
186
+
}
187
+
```
188
+
178
189
### Configure strategy in automatic reconnect
179
190
180
191
To customize the reconnect behavior, you can pass an array of numbers representing the delay in seconds before each reconnect attempt. For more granular control, pass an object that conforms to the RetryPolicy protocol.
@@ -216,6 +227,22 @@ You can customize the client's timeout and keep-alive settings via the HubConnec
216
227
|withKeepAliveInterval| 15 (seconds)|Determines the interval at which the client sends ping messages and is set directly on HubConnectionBuilder. This setting allows the server to detect hard disconnects, such as when a client unplugs their computer from the network. Sending any message from the client resets the timer to the start of the interval. If the client hasn't sent a message in the ClientTimeoutInterval set on the server, the server considers the client disconnected.|
217
228
|withServerTimeout| 30 (seconds)|Determines the interval at which the client waits for a response from the server before it considers the server disconnected. This setting is set directly on HubConnectionBuilder.|
218
229
230
+
## Configure transport
231
+
232
+
The SignalR Swift client supports three transports: LongPolling, ServerSentEvents, and WebSockets. By default, the client will use WebSockets if the server supports it, and fall back to ServerSentEvents and LongPolling if it doesn't. You can configure the client to use a specific transport by calling `withUrl(url:transport:)` while building the connection.
233
+
234
+
```swift
235
+
let connection =HubConnectionBuilder()
236
+
.withUrl(url: "https://your-signalr-server", transport: .webSockets) // use websocket only
237
+
.build()
238
+
```
239
+
240
+
```swift
241
+
let connection =HubConnectionBuilder()
242
+
.withUrl(url: "https://your-signalr-server", transport: [.webSockets, .serverSentEvents]) // use websockets and server sent events
243
+
.build()
244
+
```
245
+
219
246
## Additional resources
220
247
221
248
*[WebPack and TypeScript tutorial](xref:tutorials/signalr-typescript-webpack)
0 commit comments