add default value to namespace in socketparsable
This commit is contained in:
parent
baca9fc8da
commit
4ee196c5fb
@ -223,17 +223,13 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
_emit([event] + items)
|
_emit([event] + items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||||
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
/// an ack.
|
||||||
an ack.
|
|
||||||
*/
|
|
||||||
public func emitWithAck(event: String, _ items: AnyObject...) -> OnAckCallback {
|
public func emitWithAck(event: String, _ items: AnyObject...) -> OnAckCallback {
|
||||||
return emitWithAck(event, withItems: items)
|
return emitWithAck(event, withItems: items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Same as emitWithAck, but for Objective-C
|
||||||
Same as emitWithAck, but for Objective-C
|
|
||||||
*/
|
|
||||||
public func emitWithAck(event: String, withItems items: [AnyObject]) -> OnAckCallback {
|
public func emitWithAck(event: String, withItems items: [AnyObject]) -> OnAckCallback {
|
||||||
return createOnAck([event] + items)
|
return createOnAck([event] + items)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,7 @@ extension SocketParsable {
|
|||||||
return .Right(SocketPacket(type: type, nsp: "/"))
|
return .Right(SocketPacket(type: type, nsp: "/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var namespace: String?
|
var namespace = "/"
|
||||||
var placeholders = -1
|
var placeholders = -1
|
||||||
|
|
||||||
if type == .BinaryEvent || type == .BinaryAck {
|
if type == .BinaryEvent || type == .BinaryAck {
|
||||||
@ -119,23 +119,24 @@ extension SocketParsable {
|
|||||||
// If first you don't succeed, try again
|
// If first you don't succeed, try again
|
||||||
if case let .Right(data) = parseData("\([noPlaceholders as AnyObject])") {
|
if case let .Right(data) = parseData("\([noPlaceholders as AnyObject])") {
|
||||||
return .Right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
|
return .Right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
|
||||||
nsp: namespace ?? "/", placeholders: placeholders))
|
nsp: namespace, placeholders: placeholders))
|
||||||
} else {
|
} else {
|
||||||
return .Left(err)
|
return .Left(err)
|
||||||
}
|
}
|
||||||
case let .Right(data):
|
case let .Right(data):
|
||||||
return .Right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
|
return .Right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
|
||||||
nsp: namespace ?? "/", placeholders: placeholders))
|
nsp: namespace, placeholders: placeholders))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses data for events
|
// Parses data for events
|
||||||
private func parseData(data: String) -> Either<String, [AnyObject]> {
|
private func parseData(data: String) -> Either<String, [AnyObject]> {
|
||||||
let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if let arr = try NSJSONSerialization.JSONObjectWithData(stringData!,
|
if let arr = try NSJSONSerialization.JSONObjectWithData(stringData!,
|
||||||
options: NSJSONReadingOptions.MutableContainers) as? [AnyObject] {
|
options: NSJSONReadingOptions.MutableContainers) as? [AnyObject] {
|
||||||
return .Right(arr)
|
return .Right(arr)
|
||||||
} else {
|
} else {
|
||||||
return .Left("Expected data array")
|
return .Left("Expected data array")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user