Skip to content

Commit d50eb38

Browse files
author
FreakyCoder
authored
Merge pull request #103 from JKim0119/master
Adding functionality to stop the reconnect timer
2 parents afb8b32 + 0140b8d commit d50eb38

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

StompClientLib/Classes/StompClientLib.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
8080
public var certificateCheckEnabled = true
8181
private var urlRequest: NSURLRequest?
8282

83+
private var reconnectTimer : Timer?
84+
8385
public func sendJSONForDict(dict: AnyObject, toDestination destination: String) {
8486
do {
8587
let theJSONData = try JSONSerialization.data(withJSONObject: dict, options: JSONSerialization.WritingOptions())
@@ -456,7 +458,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
456458
// TODO: MAKE A VARIABLE TO CHECK RECONNECT OPTION IS AVAILABLE OR NOT
457459
public func reconnect(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String] = [String: String](), time: Double = 1.0, exponentialBackoff: Bool = true){
458460
if #available(iOS 10.0, *) {
459-
Timer.scheduledTimer(withTimeInterval: time, repeats: true, block: { _ in
461+
reconnectTimer = Timer.scheduledTimer(withTimeInterval: time, repeats: true, block: { _ in
460462
self.reconnectLogic(request: request, delegate: delegate
461463
, connectionHeaders: connectionHeaders)
462464
})
@@ -478,6 +480,11 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
478480
}
479481
}
480482

483+
public func stopReconnect() {
484+
reconnectTimer?.invalidate()
485+
reconnectTimer = nil
486+
}
487+
481488
private func checkConnectionHeader(connectionHeaders: [String: String] = [String: String]()) -> Bool{
482489
if (connectionHeaders.isEmpty){
483490
// No connection header

0 commit comments

Comments
 (0)