@@ -22,8 +22,9 @@ public class PusherConnection {
22
22
public var userDataFetcher : ( ( ) -> PusherUserData ) ?
23
23
public var debugLogger : ( ( String ) -> ( ) ) ?
24
24
public weak var stateChangeDelegate : ConnectionStateChangeDelegate ?
25
- public var reconnectAttemptsMax : Int = 6
25
+ public var reconnectAttemptsMax : Int ? = 6
26
26
public var reconnectAttempts : Int = 0
27
+ public var maxReconnectGapInSeconds : Int ? = nil
27
28
private var reconnectTimer : NSTimer ? = nil
28
29
internal var reconnectOperation : NSOperation ?
29
30
@@ -669,17 +670,21 @@ public class PusherConnection {
669
670
Attempt to reconnect triggered by a disconnection
670
671
*/
671
672
@objc internal func attemptReconnect( ) {
672
- if reconnectAttempts < reconnectAttemptsMax && connectionState != . Connected {
673
- connect ( )
674
- reconnectAttempts += 1
675
- let timeInterval = Double ( reconnectAttempts * reconnectAttempts) * 2.0
676
- reconnectTimer = NSTimer . scheduledTimerWithTimeInterval (
677
- timeInterval,
678
- target: self ,
679
- selector: #selector( attemptReconnect) ,
680
- userInfo: nil ,
681
- repeats: false
682
- )
673
+ if connectionState != . Connected {
674
+ if ( reconnectAttemptsMax == nil || ( reconnectAttemptsMax != nil && reconnectAttempts < reconnectAttemptsMax) ) {
675
+ connect ( )
676
+ reconnectAttempts += 1
677
+ let reconnectInterval = Double ( reconnectAttempts * reconnectAttempts) * 2.0
678
+ let timeInterval = maxReconnectGapInSeconds != nil ? max ( reconnectInterval, Double ( maxReconnectGapInSeconds!) )
679
+ : reconnectInterval
680
+ reconnectTimer = NSTimer . scheduledTimerWithTimeInterval (
681
+ timeInterval,
682
+ target: self ,
683
+ selector: #selector( attemptReconnect) ,
684
+ userInfo: nil ,
685
+ repeats: false
686
+ )
687
+ }
683
688
}
684
689
}
685
690
}
0 commit comments