Merge pull request #1059 from socketio/development

v13.3.0
This commit is contained in:
Erik Little 2018-07-29 10:30:14 -04:00 committed by GitHub
commit d03e319e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 14 deletions

View File

@ -26,7 +26,7 @@ import Dispatch
import Foundation import Foundation
/// Defines the interface for a SocketIOClient. /// Defines the interface for a SocketIOClient.
public protocol SocketIOClientSpec : class { public protocol SocketIOClientSpec : AnyObject {
// MARK: Properties // MARK: Properties
/// A handler that will be called on any event. /// A handler that will be called on any event.

View File

@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
private func createWebSocketAndConnect() { private func createWebSocketAndConnect() {
var req = URLRequest(url: urlWebSocketWithSid) var req = URLRequest(url: urlWebSocketWithSid)
addHeaders(to: &req) addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies)
ws = WebSocket(request: req) ws = WebSocket(request: req)
ws?.callbackQueue = engineQueue ws?.callbackQueue = engineQueue

View File

@ -155,9 +155,12 @@ extension SocketEngineSpec {
return com.url! return com.url!
} }
func addHeaders(to req: inout URLRequest) { func addHeaders(to req: inout URLRequest, includingCookies additionalCookies: [HTTPCookie]? = nil) {
if let cookies = cookies { var cookiesToAdd: [HTTPCookie] = cookies ?? []
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies) cookiesToAdd += additionalCookies ?? []
if !cookiesToAdd.isEmpty {
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookiesToAdd)
} }
if let extraHeaders = extraHeaders { if let extraHeaders = extraHeaders {

View File

@ -392,7 +392,7 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
private func _parseEngineMessage(_ msg: String) { private func _parseEngineMessage(_ msg: String) {
guard let packet = parseSocketMessage(msg) else { return } guard let packet = parseSocketMessage(msg) else { return }
guard packet.type != .binaryAck && packet.type != .binaryEvent else { guard !packet.type.isBinary else {
waitingPackets.append(packet) waitingPackets.append(packet)
return return

View File

@ -46,7 +46,7 @@ import Foundation
/// or call one of the `disconnectSocket` methods on this class. /// or call one of the `disconnectSocket` methods on this class.
/// ///
@objc @objc
public protocol SocketManagerSpec : class, SocketEngineClient { public protocol SocketManagerSpec : AnyObject, SocketEngineClient {
// MARK: Properties // MARK: Properties
/// Returns the socket associated with the default namespace ("/"). /// Returns the socket associated with the default namespace ("/").

View File

@ -116,7 +116,7 @@ public struct SocketPacket : CustomStringConvertible {
private func createPacketString() -> String { private func createPacketString() -> String {
let typeString = String(type.rawValue) let typeString = String(type.rawValue)
// Binary count? // Binary count?
let binaryCountString = typeString + (type == .binaryEvent || type == .binaryAck ? "\(String(binary.count))-" : "") let binaryCountString = typeString + (type.isBinary ? "\(String(binary.count))-" : "")
// Namespace? // Namespace?
let nspString = binaryCountString + (nsp != "/" ? "\(nsp)," : "") let nspString = binaryCountString + (nsp != "/" ? "\(nsp)," : "")
// Ack number? // Ack number?
@ -181,6 +181,13 @@ public extension SocketPacket {
/// Binary Ack: 6 /// Binary Ack: 6
case binaryAck case binaryAck
// MARK: Properties
/// Whether or not this type is binary
public var isBinary: Bool {
return self == .binaryAck || self == .binaryEvent
}
} }
} }

View File

@ -23,7 +23,7 @@
import Foundation import Foundation
/// Defines that a type will be able to parse socket.io-protocol messages. /// Defines that a type will be able to parse socket.io-protocol messages.
public protocol SocketParsable : class { public protocol SocketParsable : AnyObject {
// MARK: Methods // MARK: Methods
/// Called when the engine has received some binary data that should be attached to a packet. /// Called when the engine has received some binary data that should be attached to a packet.
@ -57,7 +57,7 @@ public enum SocketParsableError : Error {
} }
/// Says that a type will be able to buffer binary data before all data for an event has come in. /// Says that a type will be able to buffer binary data before all data for an event has come in.
public protocol SocketDataBufferable : class { public protocol SocketDataBufferable : AnyObject {
// MARK: Properties // MARK: Properties
/// A list of packets that are waiting for binary data. /// A list of packets that are waiting for binary data.
@ -88,7 +88,7 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer
var namespace = "/" var namespace = "/"
var placeholders = -1 var placeholders = -1
if type == .binaryEvent || type == .binaryAck { if type.isBinary {
if let holders = Int(reader.readUntilOccurence(of: "-")) { if let holders = Int(reader.readUntilOccurence(of: "-")) {
placeholders = holders placeholders = holders
} else { } else {

View File

@ -25,7 +25,7 @@
import Foundation import Foundation
/// Represents a class will log client events. /// Represents a class will log client events.
public protocol SocketLogger : class { public protocol SocketLogger : AnyObject {
// MARK: Properties // MARK: Properties
/// Whether to log or not /// Whether to log or not