tweaks
This commit is contained in:
parent
e2bf84f576
commit
c364f6a832
@ -15,7 +15,7 @@ class TestSocketIOClientConfiguration: XCTestCase {
|
|||||||
override func setUp() {
|
override func setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|
||||||
config = [.Log(false), .ForceNew(true)] as SocketIOClientConfiguration
|
config = [.Log(false), .ForceNew(true)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func testReplaceSameOption() {
|
func testReplaceSameOption() {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ extension Array where Element: AnyObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension NSCharacterSet {
|
extension NSCharacterSet {
|
||||||
class var allowedURLCharacterSet: NSCharacterSet {
|
static var allowedURLCharacterSet: NSCharacterSet {
|
||||||
return NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
return NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,9 +45,6 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
public var config: SocketIOClientConfiguration
|
public var config: SocketIOClientConfiguration
|
||||||
public var reconnects = true
|
public var reconnects = true
|
||||||
public var reconnectWait = 10
|
public var reconnectWait = 10
|
||||||
public var sid: String? {
|
|
||||||
return nsp + "#" + (engine?.sid ?? "")
|
|
||||||
}
|
|
||||||
|
|
||||||
private let ackQueue = dispatch_queue_create("com.socketio.ackQueue", DISPATCH_QUEUE_SERIAL)
|
private let ackQueue = dispatch_queue_create("com.socketio.ackQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
private let emitQueue = dispatch_queue_create("com.socketio.emitQueue", DISPATCH_QUEUE_SERIAL)
|
private let emitQueue = dispatch_queue_create("com.socketio.emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
@ -66,6 +63,10 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
|
|
||||||
var waitingPackets = [SocketPacket]()
|
var waitingPackets = [SocketPacket]()
|
||||||
|
|
||||||
|
public var sid: String? {
|
||||||
|
return nsp + "#" + (engine?.sid ?? "")
|
||||||
|
}
|
||||||
|
|
||||||
/// Type safe way to create a new SocketIOClient. opts can be omitted
|
/// Type safe way to create a new SocketIOClient. opts can be omitted
|
||||||
public init(socketURL: NSURL, config: SocketIOClientConfiguration = []) {
|
public init(socketURL: NSURL, config: SocketIOClientConfiguration = []) {
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
@ -26,6 +26,10 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct SocketPacket {
|
struct SocketPacket {
|
||||||
|
enum PacketType: Int {
|
||||||
|
case Connect, Disconnect, Event, Ack, Error, BinaryEvent, BinaryAck
|
||||||
|
}
|
||||||
|
|
||||||
private let placeholders: Int
|
private let placeholders: Int
|
||||||
|
|
||||||
private static let logType = "SocketPacket"
|
private static let logType = "SocketPacket"
|
||||||
@ -34,9 +38,8 @@ struct SocketPacket {
|
|||||||
let id: Int
|
let id: Int
|
||||||
let type: PacketType
|
let type: PacketType
|
||||||
|
|
||||||
enum PacketType: Int {
|
var binary: [NSData]
|
||||||
case Connect, Disconnect, Event, Ack, Error, BinaryEvent, BinaryAck
|
var data: [AnyObject]
|
||||||
}
|
|
||||||
|
|
||||||
var args: [AnyObject] {
|
var args: [AnyObject] {
|
||||||
if type == .Event || type == .BinaryEvent && data.count != 0 {
|
if type == .Event || type == .BinaryEvent && data.count != 0 {
|
||||||
@ -46,8 +49,6 @@ struct SocketPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var binary: [NSData]
|
|
||||||
var data: [AnyObject]
|
|
||||||
var description: String {
|
var description: String {
|
||||||
return "SocketPacket {type: \(String(type.rawValue)); data: " +
|
return "SocketPacket {type: \(String(type.rawValue)); data: " +
|
||||||
"\(String(data)); id: \(id); placeholders: \(placeholders); nsp: \(nsp)}"
|
"\(String(data)); id: \(id); placeholders: \(placeholders); nsp: \(nsp)}"
|
||||||
@ -110,27 +111,12 @@ struct SocketPacket {
|
|||||||
|
|
||||||
private func createPacketString() -> String {
|
private func createPacketString() -> String {
|
||||||
let typeString = String(type.rawValue)
|
let typeString = String(type.rawValue)
|
||||||
let binaryCountString: String
|
// Binary count?
|
||||||
let nspString: String
|
let binaryCountString = typeString + (type == .BinaryEvent || type == .BinaryAck ? String(binary.count) + "-" : "")
|
||||||
let idString: String
|
// Namespace?
|
||||||
|
let nspString = binaryCountString + (nsp != "/" ? nsp + "," : "")
|
||||||
if type == .BinaryEvent || type == .BinaryAck {
|
// Ack number?
|
||||||
binaryCountString = typeString + String(binary.count) + "-"
|
let idString = nspString + (id != -1 ? String(id) : "")
|
||||||
} else {
|
|
||||||
binaryCountString = typeString
|
|
||||||
}
|
|
||||||
|
|
||||||
if nsp != "/" {
|
|
||||||
nspString = binaryCountString + nsp + ","
|
|
||||||
} else {
|
|
||||||
nspString = binaryCountString
|
|
||||||
}
|
|
||||||
|
|
||||||
if id != -1 {
|
|
||||||
idString = nspString + String(id)
|
|
||||||
} else {
|
|
||||||
idString = nspString
|
|
||||||
}
|
|
||||||
|
|
||||||
return completeMessage(idString)
|
return completeMessage(idString)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user