Skip to content

Commit eca3806

Browse files
committed
Added isConnected function
1 parent 0cb53e5 commit eca3806

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

StompClientLib/Classes/StompClientLib.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
7272
var sessionId: String?
7373
var delegate: StompClientLibDelegate?
7474
var connectionHeaders: [String: String]?
75+
public var connection: Bool = false
7576
public var certificateCheckEnabled = true
76-
7777
private var urlRequest: NSURLRequest?
7878

7979
public func sendJSONForDict(dict: AnyObject, toDestination destination: String) {
@@ -98,6 +98,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
9898
public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]?) {
9999
self.connectionHeaders = connectionHeaders
100100
openSocketWithURLRequest(request: request, delegate: delegate)
101+
self.connection = true
101102
}
102103

103104
private func openSocket() {
@@ -339,7 +340,12 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
339340
sendFrame(command: StompCommands.commandSend, header: headersToSend, body: message as AnyObject)
340341
}
341342

343+
public func isConnected() -> Bool{
344+
return connection
345+
}
346+
342347
public func subscribe(destination: String) {
348+
connection = true
343349
subscribeToDestination(destination: destination, ackMode: .AutoMode)
344350
}
345351

@@ -366,6 +372,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
366372
}
367373

368374
public func unsubscribe(destination: String) {
375+
connection = false
369376
var headerToSend = [String: String]()
370377
headerToSend[StompCommands.commandHeaderDestinationId] = destination
371378
sendFrame(command: StompCommands.commandUnsubscribe, header: headerToSend, body: nil)
@@ -403,6 +410,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
403410
}
404411

405412
public func disconnect() {
413+
connection = false
406414
var headerToSend = [String: String]()
407415
headerToSend[StompCommands.commandDisconnect] = String(Int(NSDate().timeIntervalSince1970))
408416
sendFrame(command: StompCommands.commandDisconnect, header: headerToSend, body: nil)

0 commit comments

Comments
 (0)