This repository was archived by the owner on Jan 28, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ public final class SKRTMAPI: RTMDelegate {
5454 public var token = " xoxp-SLACK_AUTH_TOKEN "
5555 internal var options : RTMOptions
5656 var connected = false
57+ public var connectionRetryInterval : TimeInterval ? = nil
5758
5859 var ping : Double ?
5960 var pong : Double ?
@@ -86,7 +87,7 @@ public final class SKRTMAPI: RTMDelegate {
8687 success: { ( response) in
8788 self . connectWithResponse ( response)
8889 } , failure: { ( error) in
89- print ( error )
90+ self . retryConnection ( )
9091 }
9192 )
9293 } else {
@@ -97,12 +98,23 @@ public final class SKRTMAPI: RTMDelegate {
9798 success: { ( response) in
9899 self . connectWithResponse ( response)
99100 } , failure: { ( error) in
100- print ( error )
101+ self . retryConnection ( )
101102 }
102103 )
103104 }
104105 }
105106
107+ private func retryConnection( ) {
108+ guard let connectionRetryInterval = self . connectionRetryInterval else {
109+ return
110+ }
111+ let retryInterval = Double ( UInt64 ( connectionRetryInterval * Double( UInt64 . nanosecondsPerSecond) ) ) / Double( UInt64 . nanosecondsPerSecond)
112+ let delay = DispatchTime . now ( ) + retryInterval
113+ DispatchQueue . main. asyncAfter ( deadline: delay) {
114+ self . connect ( )
115+ }
116+ }
117+
106118 public func disconnect( ) {
107119 rtm. disconnect ( )
108120 }
You can’t perform that action at this time.
0 commit comments