update for beta 4
This commit is contained in:
parent
a5db13c8b5
commit
61a20cf27e
@ -66,7 +66,7 @@ public class SSLSecurity : NSObject {
|
|||||||
- returns: a representation security object to be used with
|
- returns: a representation security object to be used with
|
||||||
*/
|
*/
|
||||||
public convenience init(usePublicKeys: Bool = false) {
|
public convenience init(usePublicKeys: Bool = false) {
|
||||||
let paths = Bundle.main.pathsForResources(ofType: "cer", inDirectory: ".")
|
let paths = Bundle.main.paths(forResourcesOfType: "cer", inDirectory: ".")
|
||||||
|
|
||||||
let certs = paths.reduce([SSLCert]()) { (certs: [SSLCert], path: String) -> [SSLCert] in
|
let certs = paths.reduce([SSLCert]()) { (certs: [SSLCert], path: String) -> [SSLCert] in
|
||||||
var certs = certs
|
var certs = certs
|
||||||
@ -93,7 +93,7 @@ public class SSLSecurity : NSObject {
|
|||||||
self.usePublicKeys = usePublicKeys
|
self.usePublicKeys = usePublicKeys
|
||||||
|
|
||||||
if self.usePublicKeys {
|
if self.usePublicKeys {
|
||||||
DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosDefault).async {
|
DispatchQueue.global(qos: .default).async {
|
||||||
let pubKeys = certs.reduce([SecKey]()) { (pubKeys: [SecKey], cert: SSLCert) -> [SecKey] in
|
let pubKeys = certs.reduce([SecKey]()) { (pubKeys: [SecKey], cert: SSLCert) -> [SecKey] in
|
||||||
var pubKeys = pubKeys
|
var pubKeys = pubKeys
|
||||||
if let data = cert.certData, cert.key == nil {
|
if let data = cert.certData, cert.key == nil {
|
||||||
|
|||||||
@ -25,9 +25,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, SocketEngineWebsocket {
|
public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, SocketEngineWebsocket {
|
||||||
public let emitQueue = DispatchQueue(label: "com.socketio.engineEmitQueue", attributes: DispatchQueueAttributes.serial)
|
public let emitQueue = DispatchQueue(label: "com.socketio.engineEmitQueue", attributes: [])
|
||||||
public let handleQueue = DispatchQueue(label: "com.socketio.engineHandleQueue", attributes: DispatchQueueAttributes.serial)
|
public let handleQueue = DispatchQueue(label: "com.socketio.engineHandleQueue", attributes: [])
|
||||||
public let parseQueue = DispatchQueue(label: "com.socketio.engineParseQueue", attributes: DispatchQueueAttributes.serial)
|
public let parseQueue = DispatchQueue(label: "com.socketio.engineParseQueue", attributes: [])
|
||||||
|
|
||||||
public var connectParams: [String: AnyObject]? {
|
public var connectParams: [String: AnyObject]? {
|
||||||
didSet {
|
didSet {
|
||||||
@ -218,8 +218,8 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
return (URL(string: "http://localhost/")!, URL(string: "http://localhost/")!)
|
return (URL(string: "http://localhost/")!, URL(string: "http://localhost/")!)
|
||||||
}
|
}
|
||||||
|
|
||||||
var urlPolling = URLComponents(string: url.absoluteString!)!
|
var urlPolling = URLComponents(string: url.absoluteString)!
|
||||||
var urlWebSocket = URLComponents(string: url.absoluteString!)!
|
var urlWebSocket = URLComponents(string: url.absoluteString)!
|
||||||
var queryString = ""
|
var queryString = ""
|
||||||
|
|
||||||
urlWebSocket.path = socketPath
|
urlWebSocket.path = socketPath
|
||||||
@ -482,7 +482,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
write("", withType: .ping, withData: [])
|
write("", withType: .ping, withData: [])
|
||||||
|
|
||||||
let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
||||||
DispatchQueue.main.after(when: time) {[weak self] in self?.sendPing() }
|
DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ extension SocketEnginePollable {
|
|||||||
doLongPoll(for: req )
|
doLongPoll(for: req )
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRequest(for req: URLRequest, callbackWith callback: (Data?, URLResponse?, NSError?) -> Void) {
|
func doRequest(for req: URLRequest, callbackWith callback: (Data?, URLResponse?, Error?) -> Void) {
|
||||||
if !polling || closed || invalidated || fastUpgrade {
|
if !polling || closed || invalidated || fastUpgrade {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum JSONError : ErrorProtocol {
|
enum JSONError : Error {
|
||||||
case notArray
|
case notArray
|
||||||
case notNSDictionary
|
case notNSDictionary
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,10 +49,10 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
return nsp + "#" + (engine?.sid ?? "")
|
return nsp + "#" + (engine?.sid ?? "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private let ackQueue = DispatchQueue(label: "com.socketio.ackQueue", attributes: .serial)
|
private let ackQueue = DispatchQueue(label: "com.socketio.ackQueue", attributes: [])
|
||||||
private let emitQueue = DispatchQueue(label: "com.socketio.emitQueue", attributes: .serial)
|
private let emitQueue = DispatchQueue(label: "com.socketio.emitQueue", attributes: [])
|
||||||
private let logType = "SocketIOClient"
|
private let logType = "SocketIOClient"
|
||||||
private let parseQueue = DispatchQueue(label: "com.socketio.parseQueue", attributes: .serial)
|
private let parseQueue = DispatchQueue(label: "com.socketio.parseQueue", attributes: [])
|
||||||
|
|
||||||
private var anyHandler: ((SocketAnyEvent) -> Void)?
|
private var anyHandler: ((SocketAnyEvent) -> Void)?
|
||||||
private var currentReconnectAttempt = 0
|
private var currentReconnectAttempt = 0
|
||||||
@ -71,7 +71,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
self.options = options
|
self.options = options
|
||||||
self.socketURL = socketURL
|
self.socketURL = socketURL
|
||||||
|
|
||||||
if socketURL.absoluteString?.hasPrefix("https://") ?? false {
|
if socketURL.absoluteString.hasPrefix("https://") ?? false {
|
||||||
self.options.insertIgnore(.secure(true))
|
self.options.insertIgnore(.secure(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
|
|
||||||
let time = DispatchTime.now() + Double(Int64(timeoutAfter) * Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
let time = DispatchTime.now() + Double(Int64(timeoutAfter) * Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
||||||
|
|
||||||
handleQueue.after(when: time) {[weak self] in
|
handleQueue.asyncAfter(deadline: time) {[weak self] in
|
||||||
if let this = self, this.status != .connected && this.status != .disconnected {
|
if let this = self, this.status != .connected && this.status != .disconnected {
|
||||||
this.status = .disconnected
|
this.status = .disconnected
|
||||||
this.engine?.disconnect(reason: "Connect timeout")
|
this.engine?.disconnect(reason: "Connect timeout")
|
||||||
@ -174,7 +174,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
if timeout != 0 {
|
if timeout != 0 {
|
||||||
let time = DispatchTime.now() + Double(Int64(timeout * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
let time = DispatchTime.now() + Double(Int64(timeout * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
||||||
|
|
||||||
this.handleQueue.after(when: time) {
|
this.handleQueue.asyncAfter(deadline: time) {
|
||||||
this.ackHandlers.timeoutAck(ack, onQueue: this.handleQueue)
|
this.ackHandlers.timeoutAck(ack, onQueue: this.handleQueue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,7 +443,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
|
|
||||||
let dispatchAfter = DispatchTime.now() + Double(Int64(UInt64(reconnectWait) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
let dispatchAfter = DispatchTime.now() + Double(Int64(UInt64(reconnectWait) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
||||||
|
|
||||||
DispatchQueue.main.after(when: dispatchAfter, execute: _tryReconnect)
|
DispatchQueue.main.asyncAfter(deadline: dispatchAfter, execute: _tryReconnect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -152,7 +152,7 @@ struct SocketPacket {
|
|||||||
if dict["_placeholder"] as? Bool ?? false {
|
if dict["_placeholder"] as? Bool ?? false {
|
||||||
return binary[dict["num"] as! Int]
|
return binary[dict["num"] as! Int]
|
||||||
} else {
|
} else {
|
||||||
return dict.reduce(NSMutableDictionary(), combine: {cur, keyValue in
|
return dict.reduce(NSMutableDictionary(), {cur, keyValue in
|
||||||
cur[keyValue.0 as! NSCopying] = _fillInPlaceholders(keyValue.1)
|
cur[keyValue.0 as! NSCopying] = _fillInPlaceholders(keyValue.1)
|
||||||
return cur
|
return cur
|
||||||
})
|
})
|
||||||
@ -202,7 +202,7 @@ private extension SocketPacket {
|
|||||||
case let arr as [AnyObject]:
|
case let arr as [AnyObject]:
|
||||||
return arr.map({shred($0, binary: &binary)}) as AnyObject
|
return arr.map({shred($0, binary: &binary)}) as AnyObject
|
||||||
case let dict as NSDictionary:
|
case let dict as NSDictionary:
|
||||||
return dict.reduce(NSMutableDictionary(), combine: {cur, keyValue in
|
return dict.reduce(NSMutableDictionary(), {cur, keyValue in
|
||||||
cur[keyValue.0 as! NSCopying] = shred(keyValue.1, binary: &binary)
|
cur[keyValue.0 as! NSCopying] = shred(keyValue.1, binary: &binary)
|
||||||
return cur
|
return cur
|
||||||
})
|
})
|
||||||
|
|||||||
@ -136,7 +136,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
|||||||
private var certValidated = false
|
private var certValidated = false
|
||||||
private var didDisconnect = false
|
private var didDisconnect = false
|
||||||
private var readyToWrite = false
|
private var readyToWrite = false
|
||||||
private let mutex = Lock()
|
private let mutex = NSLock()
|
||||||
private let notificationCenter = NotificationCenter.default
|
private let notificationCenter = NotificationCenter.default
|
||||||
private var canDispatch: Bool {
|
private var canDispatch: Bool {
|
||||||
mutex.lock()
|
mutex.lock()
|
||||||
@ -145,7 +145,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
|||||||
return canWork
|
return canWork
|
||||||
}
|
}
|
||||||
//the shared processing queue used for all websocket
|
//the shared processing queue used for all websocket
|
||||||
private static let sharedWorkQueue = DispatchQueue(label: "com.vluxe.starscream.websocket", attributes: DispatchQueueAttributes.serial)
|
private static let sharedWorkQueue = DispatchQueue(label: "com.vluxe.starscream.websocket", attributes: [])
|
||||||
|
|
||||||
//used for setting protocols.
|
//used for setting protocols.
|
||||||
public init(url: URL, protocols: [String]? = nil) {
|
public init(url: URL, protocols: [String]? = nil) {
|
||||||
@ -176,7 +176,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
|||||||
public func disconnect(_ forceTimeout: TimeInterval? = nil) {
|
public func disconnect(_ forceTimeout: TimeInterval? = nil) {
|
||||||
switch forceTimeout {
|
switch forceTimeout {
|
||||||
case .some(let seconds) where seconds > 0:
|
case .some(let seconds) where seconds > 0:
|
||||||
queue.after(when: DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { [weak self] in
|
queue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { [weak self] in
|
||||||
self?.disconnectStream(nil)
|
self?.disconnectStream(nil)
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
@ -798,7 +798,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
|||||||
if len < 0 {
|
if len < 0 {
|
||||||
var error: NSError?
|
var error: NSError?
|
||||||
if let streamError = outStream.streamError {
|
if let streamError = outStream.streamError {
|
||||||
error = streamError
|
error = streamError as NSError
|
||||||
} else {
|
} else {
|
||||||
let errCode = InternalErrorCode.outputStreamWriteError.rawValue
|
let errCode = InternalErrorCode.outputStreamWriteError.rawValue
|
||||||
error = s.errorWithDetail("output stream error during write", code: errCode)
|
error = s.errorWithDetail("output stream error during write", code: errCode)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user