diff --git a/ActionCableClient.podspec b/ActionCableClient.podspec index 41e1082..c7da9ff 100644 --- a/ActionCableClient.podspec +++ b/ActionCableClient.podspec @@ -19,5 +19,5 @@ Pod::Spec.new do |s| s.source_files = 'Source/Classes/**/*' s.frameworks = 'Foundation' - s.dependency 'Starscream', '~> 3.0.3' + s.dependency 'Starscream', '~> 3.1' end diff --git a/Source/Classes/ActionCableClient.swift b/Source/Classes/ActionCableClient.swift index 19e1822..5a5e2af 100644 --- a/Source/Classes/ActionCableClient.swift +++ b/Source/Classes/ActionCableClient.swift @@ -74,7 +74,7 @@ open class ActionCableClient { open var headers : [String: String]? { get { return socket.request.allHTTPHeaderFields } set { - for (field, value) in headers ?? [:] { + for (field, value) in newValue ?? [:] { socket.request.setValue(value, forHTTPHeaderField: field) } } @@ -349,8 +349,16 @@ extension ActionCableClient { fileprivate func didDisconnect(_ error: Swift.Error?) { var attemptReconnect: Bool = true + var rejected: Bool = false var connectionError: ConnectionError? + if let error = error as? WSError { + if error.type == Starscream.ErrorType.protocolError { + print("ActionCable connection rejected: \(error)") + rejected = true; + } + } + let channels = self.channels for (_, channel) in channels { let message = Message(channelName: channel.uid, actionName: nil, messageType: MessageType.hibernateSubscription, data: nil, error: nil) @@ -364,7 +372,7 @@ extension ActionCableClient { } // Reconcile reconncetion attempt with manual disconnect - attemptReconnect = !manualDisconnectFlag && attemptReconnect + attemptReconnect = !manualDisconnectFlag && attemptReconnect && !rejected // disconnect() has not been called and error is // worthy of attempting a reconnect. diff --git a/Source/Classes/Channel.swift b/Source/Classes/Channel.swift index d3ecb6e..4dc8909 100644 --- a/Source/Classes/Channel.swift +++ b/Source/Classes/Channel.swift @@ -193,7 +193,7 @@ open class Channel: Hashable, Equatable { internal var onReceiveActionHooks: Dictionary = Dictionary() internal unowned var client: ActionCableClient internal var actionBuffer: Array = Array() - open let hashValue: Int = Int(arc4random_uniform(UInt32(Int32.max))) + public let hashValue: Int = Int(arc4random_uniform(UInt32(Int32.max))) } public func ==(lhs: Channel, rhs: Channel) -> Bool {