Skip to content

Commit

Permalink
feat: update starscream version to 4.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
leeway1208 committed Oct 17, 2023
1 parent dd2ddf6 commit 689ce99
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "leeway1208/MqttCocoaAsyncSocket" "1.0.8"
github "daltoniam/Starscream" "3.1.1"
github "daltoniam/Starscream" "4.0.6"
6 changes: 3 additions & 3 deletions CocoaMQTT.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CocoaMQTT"
s.version = "2.1.6"
s.version = "2.1.7"
s.summary = "MQTT v3.1.1 client library for iOS and OS X written with Swift 5"
s.homepage = "https://github.com/emqx/CocoaMQTT"
s.license = { :type => "MIT" }
Expand All @@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "11.0"
s.tvos.deployment_target = "10.0"
# s.watchos.deployment_target = "2.0"
s.source = { :git => "https://github.com/emqx/CocoaMQTT.git", :tag => "2.1.6"}
s.source = { :git => "https://github.com/emqx/CocoaMQTT.git", :tag => "2.1.7"}
s.default_subspec = 'Core'

s.subspec 'Core' do |ss|
Expand All @@ -23,7 +23,7 @@ Pod::Spec.new do |s|

s.subspec 'WebSockets' do |ss|
ss.dependency "CocoaMQTT/Core"
ss.dependency "Starscream", "~> 3.1.1"
ss.dependency "Starscream", "~> 4.0.6"
ss.source_files = "Source/CocoaMQTTWebSocket.swift"
end
end
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/leeway1208/MqttCocoaAsyncSocket", from: "1.0.8"),
.package(url: "https://github.com/daltoniam/Starscream.git", from: "3.1.1"),
.package(url: "https://github.com/daltoniam/Starscream.git", from: "4.0.6"),
],
targets: [
.target(name: "CocoaMQTT",
Expand Down
26 changes: 19 additions & 7 deletions Source/CocoaMQTTWebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public extension CocoaMQTTWebSocket {
}

public init(request: URLRequest) {
reference = WebSocket(request: request, protocols: ["mqtt"], stream: FoundationStream())
reference = WebSocket(request: request)
super.init()
reference.delegate = self
}
Expand All @@ -431,23 +431,35 @@ public extension CocoaMQTTWebSocket {
}
}

extension CocoaMQTTWebSocket.StarscreamConnection: SSLTrustValidator {
public func isValid(_ trust: SecTrust, domain: String?) -> Bool {
guard let delegate = self.delegate else { return false }

extension CocoaMQTTWebSocket.StarscreamConnection: CertificatePinning {
public func evaluateTrust(trust: SecTrust, domain: String?, completion: ((PinningState) -> ())) {
var result: SecTrustResultType = .unspecified
SecTrustEvaluate(trust, &result)
let e = CFErrorCreate(kCFAllocatorDefault, "FoundationSecurityError" as NSString?, Int(result.rawValue), nil)
guard let delegate = self.delegate else {
return completion(.failed(e))
}

var shouldAccept = false
let semaphore = DispatchSemaphore(value: 0)
delegate.connection(self, didReceive: trust) { result in
shouldAccept = result
semaphore.signal()
}
semaphore.wait()

return shouldAccept

if(shouldAccept){
completion(.success)
}else{
completion(.failed(e))
}
}
}

extension CocoaMQTTWebSocket.StarscreamConnection: WebSocketDelegate {
public func didReceive(event: Starscream.WebSocketEvent, client: Starscream.WebSocketClient) {
}


public func websocketDidConnect(socket: WebSocketClient) {
delegate?.connectionOpened(self)
Expand Down

0 comments on commit 689ce99

Please sign in to comment.