From b73afe0da93e3571daf32b54914ef192ec21ce6f Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Apr 2018 18:48:15 -0400 Subject: [PATCH] get rid of internal emitAck method --- Source/SocketIO/Client/SocketIOClient.swift | 19 ++++--------------- Source/SocketIO/Client/SocketRawView.swift | 4 ++-- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 0318054..f5701da 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -289,16 +289,16 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { 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 { handleClientEvent(.error, data: ["Tried emitting when not connected"]) 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 - DefaultSocketLogger.Logger.log("Emitting: \(str)", type: logType) + DefaultSocketLogger.Logger.log("Emitting: \(str), Ack: \(isAck)", type: logType) manager?.engine?.send(str, withData: packet.binary) } @@ -310,18 +310,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { /// - parameter ack: The ack number. /// - parameter with: The data for this ack. open func emitAck(_ ack: Int, with items: [Any]) { - emitAck(ack, with: items, binary: 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) + emit(items, ack: ack, binary: true, isAck: true) } /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. diff --git a/Source/SocketIO/Client/SocketRawView.swift b/Source/SocketIO/Client/SocketRawView.swift index ed4389b..809447c 100644 --- a/Source/SocketIO/Client/SocketRawView.swift +++ b/Source/SocketIO/Client/SocketRawView.swift @@ -150,7 +150,7 @@ public final class SocketRawAckView : NSObject { guard ackNum != -1 else { return } 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 { socket.handleClientEvent(.error, data: [ackNum, items, err]) } @@ -163,6 +163,6 @@ public final class SocketRawAckView : NSObject { public func with(_ items: [Any]) { guard ackNum != -1 else { return } - socket.emitAck(ackNum, with: items, binary: false) + socket.emit(items, ack: ackNum, binary: false, isAck: true) } }