first pass at socketio/socket.io-client-swift#288
This commit is contained in:
parent
cc7d96e3d5
commit
c9ac69f408
@ -15,8 +15,8 @@ class SocketEngineTest: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
client = SocketIOClient(socketURL: "")
|
||||
engine = SocketEngine(client: client, url: "", options: nil)
|
||||
client = SocketIOClient(socketURL: NSURL())
|
||||
engine = SocketEngine(client: client, url: NSURL(), options: nil)
|
||||
|
||||
client.setTestable()
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import XCTest
|
||||
@testable import SocketIOClientSwift
|
||||
|
||||
class SocketParserTest: XCTestCase {
|
||||
let testSocket = SocketIOClient(socketURL: "")
|
||||
let testSocket = SocketIOClient(socketURL: NSURL())
|
||||
|
||||
//Format key: message; namespace-data-binary-id
|
||||
static let packetTypes: Dictionary<String, (String, [AnyObject], [NSData], Int)> = [
|
||||
|
||||
@ -16,7 +16,7 @@ class SocketSideEffectTest: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
socket = SocketIOClient(socketURL: "")
|
||||
socket = SocketIOClient(socketURL: NSURL())
|
||||
socket.setTestable()
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
||||
|
||||
private let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
||||
private let logType = "SocketEngine"
|
||||
private let url: String
|
||||
private let url: NSURL
|
||||
|
||||
private var connectParams: [String: AnyObject]?
|
||||
private var pingInterval: Double?
|
||||
@ -77,7 +77,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
||||
private var selfSigned = false
|
||||
private var voipEnabled = false
|
||||
|
||||
public init(client: SocketEngineClient, url: String, options: Set<SocketIOClientOption>) {
|
||||
public init(client: SocketEngineClient, url: NSURL, options: Set<SocketIOClientOption>) {
|
||||
self.client = client
|
||||
self.url = url
|
||||
|
||||
@ -107,9 +107,20 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
||||
}
|
||||
}
|
||||
|
||||
public convenience init(client: SocketEngineClient, url: String, options: NSDictionary?) {
|
||||
self.init(client: client, url: url,
|
||||
options: options?.toSocketOptionsSet() ?? [])
|
||||
public convenience init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) {
|
||||
self.init(client: client, url: url, options: options?.toSocketOptionsSet() ?? [])
|
||||
}
|
||||
|
||||
@available(*, deprecated=5.3)
|
||||
public convenience init(client: SocketEngineClient, urlString: String, options: Set<SocketIOClientOption>) {
|
||||
guard let url = NSURL(string: urlString) else { fatalError("Incorrect url") }
|
||||
self.init(client: client, url: url, options: options)
|
||||
}
|
||||
|
||||
@available(*, deprecated=5.3)
|
||||
public convenience init(client: SocketEngineClient, urlString: String, options: NSDictionary?) {
|
||||
guard let url = NSURL(string: urlString) else { fatalError("Incorrect url") }
|
||||
self.init(client: client, url: url, options: options?.toSocketOptionsSet() ?? [])
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -193,7 +204,16 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
||||
return ("", "")
|
||||
}
|
||||
|
||||
let socketURL = "\(url)\(socketPath)/?transport="
|
||||
let absURL = url.absoluteString["https?://"] <~ ""
|
||||
let baseURL: String
|
||||
|
||||
if absURL.hasSuffix("/") {
|
||||
baseURL = String(absURL.characters.dropLast())
|
||||
} else {
|
||||
baseURL = absURL
|
||||
}
|
||||
|
||||
let socketURL = "\(baseURL)\(socketPath)/?transport="
|
||||
var urlPolling: String
|
||||
var urlWebSocket: String
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ import Foundation
|
||||
var urlWebSocket: String { get }
|
||||
var websocket: Bool { get }
|
||||
|
||||
init(client: SocketEngineClient, url: String, options: NSDictionary?)
|
||||
init(client: SocketEngineClient, url: NSURL, options: NSDictionary?)
|
||||
|
||||
func close(reason: String)
|
||||
func didError(error: String)
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
import Foundation
|
||||
|
||||
public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable {
|
||||
public let socketURL: String
|
||||
public let socketURL: NSURL
|
||||
|
||||
public private(set) var engine: SocketEngineSpec?
|
||||
public private(set) var status = SocketIOClientStatus.NotConnected
|
||||
@ -59,21 +59,14 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
||||
/**
|
||||
Type safe way to create a new SocketIOClient. opts can be omitted
|
||||
*/
|
||||
public init(socketURL: String, options: Set<SocketIOClientOption> = []) {
|
||||
public init(socketURL: NSURL, options: Set<SocketIOClientOption> = []) {
|
||||
self.options = options
|
||||
self.socketURL = socketURL
|
||||
|
||||
if socketURL.hasPrefix("https://") {
|
||||
if socketURL.absoluteString.hasPrefix("https://") {
|
||||
self.options.insertIgnore(.Secure(true))
|
||||
}
|
||||
|
||||
var cleanedURL = socketURL["https?://"] <~ ""
|
||||
|
||||
if cleanedURL.hasSuffix("/") {
|
||||
cleanedURL = String(cleanedURL.characters.dropLast())
|
||||
}
|
||||
|
||||
self.socketURL = cleanedURL
|
||||
|
||||
for option in options {
|
||||
switch option {
|
||||
case let .ConnectParams(params):
|
||||
@ -106,11 +99,24 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
||||
|
||||
/**
|
||||
Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity.
|
||||
If using Swift it's recommended to use `init(var socketURL: String, options: Set<SocketIOClientOption>)`
|
||||
If using Swift it's recommended to use `init(var socketURL: NSURL, options: Set<SocketIOClientOption>)`
|
||||
*/
|
||||
public convenience init(socketURL: String, options: NSDictionary?) {
|
||||
self.init(socketURL: socketURL,
|
||||
options: options?.toSocketOptionsSet() ?? [])
|
||||
public convenience init(socketURL: NSURL, options: NSDictionary?) {
|
||||
self.init(socketURL: socketURL, options: options?.toSocketOptionsSet() ?? [])
|
||||
}
|
||||
|
||||
/// Please use the NSURL based init
|
||||
@available(*, deprecated=5.3)
|
||||
public convenience init(socketURLString: String, options: Set<SocketIOClientOption> = []) {
|
||||
guard let url = NSURL(string: socketURLString) else { fatalError("Incorrect url") }
|
||||
self.init(socketURL: url, options: options)
|
||||
}
|
||||
|
||||
/// Please use the NSURL based init
|
||||
@available(*, deprecated=5.3)
|
||||
public convenience init(socketURLString: String, options: NSDictionary?) {
|
||||
guard let url = NSURL(string: socketURLString) else { fatalError("Incorrect url") }
|
||||
self.init(socketURL: url, options: options?.toSocketOptionsSet() ?? [])
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user