Skip to content

Commit

Permalink
Merge pull request #56 from Erhannis/master
Browse files Browse the repository at this point in the history
String body parameter and ':'-in-header-value fix
WrathChaos authored Jul 18, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents d0c63ea + b1ba029 commit 3b2fea7
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Example/StompClientLib.swift
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public enum StompAckMode {

// Fundamental Protocols
public protocol StompClientLibDelegate {
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header:[String:String]?, withDestination destination: String)
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header:[String:String]?, withDestination destination: String)

func stompClientDidDisconnect(client: StompClientLib!)
func stompClientDidConnect(client: StompClientLib!)
@@ -298,7 +298,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
// Response
if let delegate = delegate {
DispatchQueue.main.async(execute: {
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), akaStringBody: body, withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
})
}
} else if command == StompCommands.responseFrameReceipt { //
3 changes: 2 additions & 1 deletion Example/StompClientLib/ViewController.swift
Original file line number Diff line number Diff line change
@@ -49,9 +49,10 @@ class ViewController: UIViewController, StompClientLibDelegate {
print("Socket is Disconnected")
}

func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
print("DESTIONATION : \(destination)")
print("JSON BODY : \(String(describing: jsonBody))")
print("STRING BODY : \(stringBody ?? "nil")")
}

func stompClientJSONBody(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -114,9 +114,10 @@ print("Socket is Disconnected")

Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function
```ruby
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
print("Destination : \(destination)")
print("JSON Body : \(String(describing: jsonBody))")
print("String Body : \(stringBody ?? "nil")")
}
```

6 changes: 3 additions & 3 deletions StompClientLib/Classes/StompClientLib.swift
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public enum StompAckMode {

// Fundamental Protocols
public protocol StompClientLibDelegate {
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header:[String:String]?, withDestination destination: String)
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header:[String:String]?, withDestination destination: String)

func stompClientDidDisconnect(client: StompClientLib!)
func stompClientDidConnect(client: StompClientLib!)
@@ -163,7 +163,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
} else {
let parts = line.components(separatedBy: ":")
if let key = parts.first {
headers[key] = parts.last
headers[key] = parts.dropFirst().joined(separator: ":")
}
}
}
@@ -296,7 +296,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
// Response
if let delegate = delegate {
DispatchQueue.main.async(execute: {
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), akaStringBody: body, withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
})
}
} else if command == StompCommands.responseFrameReceipt { //

0 comments on commit 3b2fea7

Please sign in to comment.