Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code and fix support spring 2.1.x #65

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Example/StompClientLib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,12 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
}
}

public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually without header still would be useful. It should stay with overload methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you right, but I keep the same function with default connectionHeaders properties with null value with one function for the same logic, don't need override. With default connectionHeaders value in function define, you can use with without header or not, like

Without headers with defaults value is null:
socketClient.openSocketWithURLRequest(request: request, delegate: delegate)

With headers:
socketClient.openSocketWithURLRequest(request: request, delegate: delegate, connectionHeaders: headers)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome answer :) Have you tested it? Does it work with your way? If it is, I will merge it and publish a new version 🎉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I have tested it with my project.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job :) I'm gonna test it and release it soon

public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]? = nil) {
self.connectionHeaders = connectionHeaders
self.delegate = delegate
self.urlRequest = request
// Opening the socket
openSocket()
}

public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]?) {
self.connectionHeaders = connectionHeaders
openSocketWithURLRequest(request: request, delegate: delegate)
self.connection = true
}

Expand Down Expand Up @@ -136,8 +132,10 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
private func connect() {
if socket?.readyState == .OPEN {
// Support for Spring Boot 2.1.x
if (connectionHeaders == nil) {
if connectionHeaders == nil {
connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]
} else {
connectionHeaders?[StompCommands.commandHeaderAcceptVersion] = "1.1,1.2"
}
// at the moment only anonymous logins
self.sendFrame(command: StompCommands.commandConnect, header: connectionHeaders, body: nil)
Expand Down
15 changes: 7 additions & 8 deletions StompClientLib/Classes/StompClientLib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,12 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
}
}

public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate) {
public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]? = nil) {
self.connectionHeaders = connectionHeaders
self.delegate = delegate
self.urlRequest = request
// Opening the socket
openSocket()
}

public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]?) {
self.connectionHeaders = connectionHeaders
openSocketWithURLRequest(request: request, delegate: delegate)
self.connection = true
}

Expand Down Expand Up @@ -136,8 +132,10 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
private func connect() {
if socket?.readyState == .OPEN {
// Support for Spring Boot 2.1.x
if (connectionHeaders == nil) {
connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]
if connectionHeaders == nil {
connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]
} else {
connectionHeaders?[StompCommands.commandHeaderAcceptVersion] = "1.1,1.2"
}
// at the moment only anonymous logins
self.sendFrame(command: StompCommands.commandConnect, header: connectionHeaders, body: nil)
Expand Down Expand Up @@ -496,3 +494,4 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
}
}
}