Skip to content

Commit 17275c2

Browse files
committed
Add some more docs about how reconnection works
1 parent bc0d195 commit 17275c2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ class ViewController: UIViewController, ConnectionStateChangeDelegate {
206206
}
207207
```
208208

209+
The different states that the connection can be in are:
210+
211+
* `Connecting` - the connection is about to attempt to be made
212+
* `Connected` - the connection has been successfully made
213+
* `Disconnecting` - the connection has been instructed to disconnect and it is just about to do so
214+
* `Disconnected` - the connection has disconnected and no attempt will be made to reconnect automatically
215+
* `Reconnecting` - an attempt is going to be made to try and re-establish the connection
216+
* `ReconnectingWhenNetworkBecomesReachable` - when the network becomes reachable an attempt will be made to reconnect
217+
218+
209219
### Reconnection
210220

211221
There are three main ways in which a disconnection can occur:
@@ -222,6 +232,12 @@ If the Pusher servers close the websocket then the library will attempt to recon
222232

223233
All of this is the case if you have the client option of `autoReconnect` set as `true`, which it is by default. If the reconnection strategies are not suitable for your use case then you can set `autoReconnect` to `false` and implement your own reconnection strategy based on the connection state changes.
224234

235+
There are a couple of properties on the connection (`PusherConnection`) that you can set that affect how the reconnection behaviour works. These are:
236+
237+
* `public var reconnectAttemptsMax: Int? = 6` - if you set this to `nil` then there is no maximum number of reconnect attempts and so attempts will continue to be made with an exponential backoff (based on number of attempts), otherwise only as many attempts as this property's value will be made before the connection's state moves to `.Disconnected`
238+
* `public var maxReconnectGapInSeconds: Double? = nil` - if you want to set a maximum length of time (in seconds) between reconnect attempts then set this property appropriately
239+
240+
Note that the number of reconnect attempts gets reset to 0 as soon as a successful connection is made.
225241

226242
## Subscribing
227243

0 commit comments

Comments
 (0)