get rid of internal emitAck method

This commit is contained in:
Erik Little 2018-04-01 18:48:15 -04:00
parent be43b0ab3c
commit b73afe0da9
No known key found for this signature in database
GPG Key ID: B8E1F067FE8DCAAF
2 changed files with 6 additions and 17 deletions

View File

@ -289,16 +289,16 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
return createOnAck([event] + items) return createOnAck([event] + items)
} }
func emit(_ data: [Any], ack: Int? = nil, binary: Bool = true) { func emit(_ data: [Any], ack: Int? = nil, binary: Bool = true, isAck: Bool = false) {
guard status == .connected else { guard status == .connected else {
handleClientEvent(.error, data: ["Tried emitting when not connected"]) handleClientEvent(.error, data: ["Tried emitting when not connected"])
return return
} }
let packet = SocketPacket.packetFromEmit(data, id: ack ?? -1, nsp: nsp, ack: false, checkForBinary: binary) let packet = SocketPacket.packetFromEmit(data, id: ack ?? -1, nsp: nsp, ack: isAck, checkForBinary: binary)
let str = packet.packetString let str = packet.packetString
DefaultSocketLogger.Logger.log("Emitting: \(str)", type: logType) DefaultSocketLogger.Logger.log("Emitting: \(str), Ack: \(isAck)", type: logType)
manager?.engine?.send(str, withData: packet.binary) manager?.engine?.send(str, withData: packet.binary)
} }
@ -310,18 +310,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
/// - parameter ack: The ack number. /// - parameter ack: The ack number.
/// - parameter with: The data for this ack. /// - parameter with: The data for this ack.
open func emitAck(_ ack: Int, with items: [Any]) { open func emitAck(_ ack: Int, with items: [Any]) {
emitAck(ack, with: items, binary: true) emit(items, ack: ack, binary: true, isAck: true)
}
func emitAck(_ ack: Int, with items: [Any], binary: Bool) {
guard status == .connected else { return }
let packet = SocketPacket.packetFromEmit(items, id: ack, nsp: nsp, ack: true, checkForBinary: binary)
let str = packet.packetString
DefaultSocketLogger.Logger.log("Emitting Ack: \(str)", type: logType)
manager?.engine?.send(str, withData: packet.binary)
} }
/// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called.

View File

@ -150,7 +150,7 @@ public final class SocketRawAckView : NSObject {
guard ackNum != -1 else { return } guard ackNum != -1 else { return }
do { do {
socket.emitAck(ackNum, with: try items.map({ try $0.socketRepresentation() }), binary: false) socket.emit(try items.map({ try $0.socketRepresentation() }), ack: ackNum, binary: false, isAck: true)
} catch let err { } catch let err {
socket.handleClientEvent(.error, data: [ackNum, items, err]) socket.handleClientEvent(.error, data: [ackNum, items, err])
} }
@ -163,6 +163,6 @@ public final class SocketRawAckView : NSObject {
public func with(_ items: [Any]) { public func with(_ items: [Any]) {
guard ackNum != -1 else { return } guard ackNum != -1 else { return }
socket.emitAck(ackNum, with: items, binary: false) socket.emit(items, ack: ackNum, binary: false, isAck: true)
} }
} }