Skip to content

Commit

Permalink
Swift 4.0 and Starscream 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
plarson committed Oct 17, 2017
1 parent 9a6c359 commit d2332b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ActionCableClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/danielrhodes/Swift-ActionCableClient.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/danielrhodes'

s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.requires_arc = true

s.source_files = 'Source/Classes/**/*'
s.frameworks = 'Foundation'
s.dependency 'Starscream', '~> 2.0.0'
s.dependency 'Starscream', '~> 3.0.0'
end
8 changes: 5 additions & 3 deletions ActionCableClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
TargetAttributes = {
86D4510C1DC31840006A516E = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
86D451321DC3189D006A516E = {
Expand Down Expand Up @@ -504,7 +504,8 @@
PRODUCT_NAME = ActionCableClient;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -525,7 +526,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.danielrhodes.ActionCableClient;
PRODUCT_NAME = ActionCableClient;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
28 changes: 14 additions & 14 deletions Source/Classes/ActionCableClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@ open class ActionCableClient {
//MARK: Properties
open var isConnected : Bool { return socket.isConnected }
open var url: Foundation.URL { return socket.currentURL }

open var headers : [String: String] {
get { return socket.headers }
set { socket.headers = newValue }
}

open var origin : String? {
get { return socket.origin }
set { socket.origin = newValue }
}


/// Initialize an ActionCableClient.
///
/// Each client represents one connection to the server.
Expand All @@ -91,9 +81,19 @@ open class ActionCableClient {
/// ```swift
/// let client = ActionCableClient(URL: NSURL(string: "ws://localhost:3000/cable")!)
/// ```
public required init(url: URL) {
public required init(url: URL, headers: [String: String]? = nil, origin : String? = nil) {
/// Setup Initialize Socket
socket = WebSocket(url: url)
var request = URLRequest(url: url)

if let origin = origin {
request.setValue(origin, forHTTPHeaderField: "Origin")
}

for (field, value) in headers ?? [:] {
request.setValue(value, forHTTPHeaderField: field)
}

socket = WebSocket(request: request)
setupWebSocket()
}

Expand Down Expand Up @@ -298,7 +298,7 @@ extension ActionCableClient {
extension ActionCableClient {

fileprivate func setupWebSocket() {
self.socket.onConnect = { [weak self] in self!.didConnect() }
self.socket.onConnect = { [weak self] in self!.didConnect() } as (() -> Void)
self.socket.onDisconnect = { [weak self] (error: Swift.Error?) in self!.didDisconnect(error) }
self.socket.onText = { [weak self] (text: String) in self!.onText(text) }
self.socket.onData = { [weak self] (data: Data) in self!.onData(data) }
Expand Down
6 changes: 3 additions & 3 deletions Source/Classes/RetryHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public enum RetryStrategy {
internal class RetryHandler : NSObject {
var retries : Int = 0
var strategy: RetryStrategy
var callback: ((Void) -> (Void))?
var callback: (() -> (Void))?
var timer: Timer?

internal required init(strategy : RetryStrategy) {
self.strategy = strategy
}

func retry(_ callback: @escaping ((Void) -> (Void))) {
func retry(_ callback: @escaping (() -> (Void))) {
self.retries += 1

// Save callback
Expand All @@ -78,7 +78,7 @@ internal class RetryHandler : NSObject {
}
}

internal func fire(_ timer : Timer) {
@objc internal func fire(_ timer : Timer) {

if let callback = self.callback {
callback()
Expand Down

0 comments on commit d2332b7

Please sign in to comment.