@@ -39,6 +39,7 @@ public protocol RTMWebSocket {
3939public protocol RTMAdapter : class {
4040 func initialSetup( json: [ String : Any ] , instance: SKRTMAPI )
4141 func notificationForEvent( _ event: Event , type: EventType , instance: SKRTMAPI )
42+ func connectionClosed( with error: Error , instance: SKRTMAPI )
4243}
4344
4445public protocol RTMDelegate : class {
@@ -53,8 +54,7 @@ public final class SKRTMAPI: RTMDelegate {
5354 public var adapter : RTMAdapter ?
5455 public var token = " xoxp-SLACK_AUTH_TOKEN "
5556 internal var options : RTMOptions
56- var connected = false
57- public var connectionRetryInterval : TimeInterval ? = nil
57+ public private( set) var connected = false
5858
5959 var ping : Double ?
6060 var pong : Double ?
@@ -87,7 +87,7 @@ public final class SKRTMAPI: RTMDelegate {
8787 success: { ( response) in
8888 self . connectWithResponse ( response)
8989 } , failure: { ( error) in
90- self . retryConnection ( )
90+ self . adapter ? . connectionClosed ( with : error , instance : self )
9191 }
9292 )
9393 } else {
@@ -98,23 +98,12 @@ public final class SKRTMAPI: RTMDelegate {
9898 success: { ( response) in
9999 self . connectWithResponse ( response)
100100 } , failure: { ( error) in
101- self . retryConnection ( )
101+ self . adapter ? . connectionClosed ( with : error , instance : self )
102102 }
103103 )
104104 }
105105 }
106106
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-
118107 public func disconnect( ) {
119108 rtm. disconnect ( )
120109 }
@@ -225,6 +214,8 @@ public final class SKRTMAPI: RTMDelegate {
225214 connected = false
226215 if options. reconnect {
227216 connect ( )
217+ } else {
218+ adapter? . connectionClosed ( with: SlackError . rtmConnectionError, instance: self )
228219 }
229220 }
230221
0 commit comments