From a4b334b6f203ba6dcb6de99b3a6d7cffce0f3908 Mon Sep 17 00:00:00 2001 From: Valentin Slawicek Date: Wed, 7 Nov 2018 12:37:48 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Don=E2=80=99t=20create=20empty=20closures?= =?UTF-8?q?=20when=20we=20don=E2=80=99t=20need=20them.=20Fixes=20https://g?= =?UTF-8?q?ithub.com/socketio/socket.io-client-swift/issues/1118.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SocketIO/Client/SocketIOClient.swift | 10 +++++----- Source/SocketIO/Client/SocketIOClientSpec.swift | 2 +- Source/SocketIO/Engine/SocketEngine.swift | 14 +++++++------- Source/SocketIO/Engine/SocketEnginePollable.swift | 6 +++--- Source/SocketIO/Engine/SocketEngineSpec.swift | 4 ++-- Source/SocketIO/Engine/SocketEngineWebsocket.swift | 6 +++--- Source/SocketIO/Manager/SocketManager.swift | 2 +- Source/SocketIO/Util/SocketTypes.swift | 4 ++-- Tests/TestSocketIO/SocketMangerTest.swift | 2 +- Tests/TestSocketIO/SocketSideEffectTest.swift | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index f7245528..000b61f1 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -230,7 +230,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { /// - parameter event: The event to send. /// - parameter items: The items to send with this event. May be left out. /// - parameter completion: Callback called on transport write completion. - open func emit(_ event: String, _ items: SocketData..., completion: @escaping () -> ()) { + open func emit(_ event: String, _ items: SocketData..., completion: @escaping (() -> ())? = nil) { do { try emit(event, with: items.map({ try $0.socketRepresentation() }), completion: completion) } catch { @@ -256,7 +256,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { /// - parameter items: The items to send with this event. Send an empty array to send no data. /// - parameter completion: Callback called on transport write completion. @objc - open func emit(_ event: String, with items: [Any], completion: @escaping () -> ()) { + open func emit(_ event: String, with items: [Any], completion: @escaping (() -> ())? = nil) { emit([event] + items, completion: completion) } @@ -317,10 +317,10 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { ack: Int? = nil, binary: Bool = true, isAck: Bool = false, - completion: @escaping () -> () = {} + completion: @escaping (() -> ())? = nil ) { // wrap the completion handler so it always runs async via handlerQueue - let wrappedCompletion = {[weak self] in + let wrappedCompletion: (() -> ())? = (completion == nil) ? nil : {[weak self] in guard let this = self else { return } this.manager?.handleQueue.async { completion() @@ -328,7 +328,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { } guard status == .connected else { - wrappedCompletion() + wrappedCompletion?() handleClientEvent(.error, data: ["Tried emitting when not connected"]) return } diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index 80e1e6a1..c9c6c245 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -109,7 +109,7 @@ public protocol SocketIOClientSpec : AnyObject { /// - parameter event: The event to send. /// - parameter items: The items to send with this event. May be left out. /// - parameter completion: Callback called on transport write completion. - func emit(_ event: String, _ items: SocketData..., completion: @escaping () -> ()) + func emit(_ event: String, _ items: SocketData..., completion: @escaping (() -> ())? = nil) /// Call when you wish to tell the server that you've received the event for `ack`. /// diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 9466a9e5..82d6c2cb 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -346,7 +346,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So if polling { disconnectPolling(reason: reason) } else { - sendWebSocketMessage("", withType: .close, withData: [], completion: {}) + sendWebSocketMessage("", withType: .close, withData: [], completion: nil) closeOutEngine(reason: reason) } } @@ -372,7 +372,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So DefaultSocketLogger.Logger.log("Switching to WebSockets", type: SocketEngine.logType) - sendWebSocketMessage("", withType: .upgrade, withData: [], completion: {}) + sendWebSocketMessage("", withType: .upgrade, withData: [], completion: nil) polling = false fastUpgrade = false probing = false @@ -390,7 +390,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So DefaultSocketLogger.Logger.log("Flushing probe wait", type: SocketEngine.logType) for waiter in probeWait { - write(waiter.msg, withType: waiter.type, withData: waiter.data, completion:waiter.completion) + write(waiter.msg, withType: waiter.type, withData: waiter.data, completion: waiter.completion) } probeWait.removeAll(keepingCapacity: false) @@ -550,7 +550,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So } pongsMissed += 1 - write("", withType: .ping, withData: [], completion: {}) + write("", withType: .ping, withData: [], completion: nil) engineQueue.asyncAfter(deadline: .now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in // Make sure not to ping old connections @@ -606,7 +606,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So DefaultSocketLogger.Logger.log("Upgrading transport to WebSockets", type: SocketEngine.logType) fastUpgrade = true - sendPollMessage("", withType: .noop, withData: [], completion: {}) + sendPollMessage("", withType: .noop, withData: [], completion: nil) // After this point, we should not send anymore polling messages } } @@ -617,10 +617,10 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So /// - parameter type: The type of this message. /// - parameter data: Any data that this message has. /// - parameter completion: Callback called on transport write completion. - open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping () -> ()) { + open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())? = nil) { engineQueue.async { guard self.connected else { - completion() + completion?() return } guard !self.probing else { diff --git a/Source/SocketIO/Engine/SocketEnginePollable.swift b/Source/SocketIO/Engine/SocketEnginePollable.swift index 7e093071..16db822f 100644 --- a/Source/SocketIO/Engine/SocketEnginePollable.swift +++ b/Source/SocketIO/Engine/SocketEnginePollable.swift @@ -65,7 +65,7 @@ public protocol SocketEnginePollable : SocketEngineSpec { /// - parameter message: The message to send. /// - parameter withType: The type of message to send. /// - parameter withData: The data associated with this message. - func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping () -> ()) + func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping (() -> ())?) /// Call to stop polling and invalidate the URLSession. func stopPolling() @@ -75,7 +75,7 @@ public protocol SocketEnginePollable : SocketEngineSpec { extension SocketEnginePollable { func createRequestForPostWithPostWait() -> URLRequest { defer { - for packet in postWait { packet.completion() } + for packet in postWait { packet.completion?() } postWait.removeAll(keepingCapacity: true) } @@ -219,7 +219,7 @@ extension SocketEnginePollable { /// - parameter withType: The type of message to send. /// - parameter withData: The data associated with this message. /// - parameter completion: Callback called on transport write completion. - public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping () -> ()) { + public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping (() -> ())? = nil) { DefaultSocketLogger.Logger.log("Sending poll: \(message) as type: \(type.rawValue)", type: "SocketEnginePolling") postWait.append((String(type.rawValue) + message, completion)) diff --git a/Source/SocketIO/Engine/SocketEngineSpec.swift b/Source/SocketIO/Engine/SocketEngineSpec.swift index f97490e3..52528156 100644 --- a/Source/SocketIO/Engine/SocketEngineSpec.swift +++ b/Source/SocketIO/Engine/SocketEngineSpec.swift @@ -138,7 +138,7 @@ import Starscream /// - parameter type: The type of this message. /// - parameter data: Any data that this message has. /// - parameter completion: Callback called on transport write completion. - func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping () -> ()) + func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())?) } extension SocketEngineSpec { @@ -180,7 +180,7 @@ extension SocketEngineSpec { } /// Send an engine message (4) - func send(_ msg: String, withData datas: [Data], completion: @escaping () -> () = {}) { + func send(_ msg: String, withData datas: [Data], completion: @escaping (() -> ())? = nil) { write(msg, withType: .message, withData: datas, completion: completion) } } diff --git a/Source/SocketIO/Engine/SocketEngineWebsocket.swift b/Source/SocketIO/Engine/SocketEngineWebsocket.swift index 0ded9a44..7fad5bc2 100644 --- a/Source/SocketIO/Engine/SocketEngineWebsocket.swift +++ b/Source/SocketIO/Engine/SocketEngineWebsocket.swift @@ -41,14 +41,14 @@ public protocol SocketEngineWebsocket : SocketEngineSpec { func sendWebSocketMessage(_ str: String, withType type: SocketEnginePacketType, withData datas: [Data], - completion: @escaping () -> ()) + completion: @escaping (() -> ())?) } // WebSocket methods extension SocketEngineWebsocket { func probeWebSocket() { if ws?.isConnected ?? false { - sendWebSocketMessage("probe", withType: .ping, withData: [], completion: {}) + sendWebSocketMessage("probe", withType: .ping, withData: [], completion: nil) } } @@ -63,7 +63,7 @@ extension SocketEngineWebsocket { public func sendWebSocketMessage(_ str: String, withType type: SocketEnginePacketType, withData datas: [Data], - completion: @escaping () -> () + completion: @escaping (() -> ())? ) { DefaultSocketLogger.Logger.log("Sending ws: \(str) as type: \(type.rawValue)", type: "SocketEngineWebSocket") diff --git a/Source/SocketIO/Manager/SocketManager.swift b/Source/SocketIO/Manager/SocketManager.swift index 19c6c9e7..e348eed3 100644 --- a/Source/SocketIO/Manager/SocketManager.swift +++ b/Source/SocketIO/Manager/SocketManager.swift @@ -286,7 +286,7 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa /// - parameter items: The data to send with this event. open func emitAll(_ event: String, withItems items: [Any]) { forAll {socket in - socket.emit(event, with: items, completion: {}) + socket.emit(event, with: items, completion: nil) } } diff --git a/Source/SocketIO/Util/SocketTypes.swift b/Source/SocketIO/Util/SocketTypes.swift index f8cdc050..7bb65173 100644 --- a/Source/SocketIO/Util/SocketTypes.swift +++ b/Source/SocketIO/Util/SocketTypes.swift @@ -74,10 +74,10 @@ public typealias AckCallback = ([Any]) -> () public typealias NormalCallback = ([Any], SocketAckEmitter) -> () /// A typealias for a queued POST -public typealias Post = (msg: String, completion: (() -> ())) +public typealias Post = (msg: String, completion: (() -> ())?) typealias JSON = [String: Any] -typealias Probe = (msg: String, type: SocketEnginePacketType, data: [Data], completion: (() -> ())) +typealias Probe = (msg: String, type: SocketEnginePacketType, data: [Data], completion: (() -> ())?) typealias ProbeWaitQueue = [Probe] enum Either { diff --git a/Tests/TestSocketIO/SocketMangerTest.swift b/Tests/TestSocketIO/SocketMangerTest.swift index fc5ad21e..9ac3c408 100644 --- a/Tests/TestSocketIO/SocketMangerTest.swift +++ b/Tests/TestSocketIO/SocketMangerTest.swift @@ -198,7 +198,7 @@ public class TestSocket : SocketIOClient { super.didDisconnect(reason: reason) } - public override func emit(_ event: String, with items: [Any], completion: @escaping () -> ()) { + public override func emit(_ event: String, with items: [Any], completion: @escaping (() -> ())?) { expectations[ManagerExpectation.emitAllEventCalled]?.fulfill() expectations[ManagerExpectation.emitAllEventCalled] = nil diff --git a/Tests/TestSocketIO/SocketSideEffectTest.swift b/Tests/TestSocketIO/SocketSideEffectTest.swift index 72c43f99..8f1bef9e 100644 --- a/Tests/TestSocketIO/SocketSideEffectTest.swift +++ b/Tests/TestSocketIO/SocketSideEffectTest.swift @@ -511,5 +511,5 @@ class TestEngine : SocketEngineSpec { func flushWaitingForPostToWebSocket() { } func parseEngineData(_ data: Data) { } func parseEngineMessage(_ message: String) { } - func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping () -> ()) { } + func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())?) { } } From 8f94c038d8c120d57ce9fb4bffc0a95512845e04 Mon Sep 17 00:00:00 2001 From: Valentin Slawicek Date: Wed, 7 Nov 2018 12:47:55 +0100 Subject: [PATCH 2/3] Fix build --- Source/SocketIO/Client/SocketIOClient.swift | 8 ++++---- Source/SocketIO/Client/SocketIOClientSpec.swift | 2 +- Source/SocketIO/Engine/SocketEngine.swift | 2 +- Source/SocketIO/Engine/SocketEnginePollable.swift | 4 ++-- Source/SocketIO/Engine/SocketEngineSpec.swift | 4 ++-- Source/SocketIO/Engine/SocketEngineWebsocket.swift | 4 ++-- Tests/TestSocketIO/SocketMangerTest.swift | 2 +- Tests/TestSocketIO/SocketSideEffectTest.swift | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 000b61f1..ef83bcdd 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -230,7 +230,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { /// - parameter event: The event to send. /// - parameter items: The items to send with this event. May be left out. /// - parameter completion: Callback called on transport write completion. - open func emit(_ event: String, _ items: SocketData..., completion: @escaping (() -> ())? = nil) { + open func emit(_ event: String, _ items: SocketData..., completion: (() -> ())? = nil) { do { try emit(event, with: items.map({ try $0.socketRepresentation() }), completion: completion) } catch { @@ -256,7 +256,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { /// - parameter items: The items to send with this event. Send an empty array to send no data. /// - parameter completion: Callback called on transport write completion. @objc - open func emit(_ event: String, with items: [Any], completion: @escaping (() -> ())? = nil) { + open func emit(_ event: String, with items: [Any], completion: (() -> ())? = nil) { emit([event] + items, completion: completion) } @@ -317,13 +317,13 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { ack: Int? = nil, binary: Bool = true, isAck: Bool = false, - completion: @escaping (() -> ())? = nil + completion: (() -> ())? = nil ) { // wrap the completion handler so it always runs async via handlerQueue let wrappedCompletion: (() -> ())? = (completion == nil) ? nil : {[weak self] in guard let this = self else { return } this.manager?.handleQueue.async { - completion() + completion!() } } diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index c9c6c245..f2658a8c 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -109,7 +109,7 @@ public protocol SocketIOClientSpec : AnyObject { /// - parameter event: The event to send. /// - parameter items: The items to send with this event. May be left out. /// - parameter completion: Callback called on transport write completion. - func emit(_ event: String, _ items: SocketData..., completion: @escaping (() -> ())? = nil) + func emit(_ event: String, _ items: SocketData..., completion: (() -> ())?) /// Call when you wish to tell the server that you've received the event for `ack`. /// diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 82d6c2cb..ee3af223 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -617,7 +617,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So /// - parameter type: The type of this message. /// - parameter data: Any data that this message has. /// - parameter completion: Callback called on transport write completion. - open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())? = nil) { + open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())? = nil) { engineQueue.async { guard self.connected else { completion?() diff --git a/Source/SocketIO/Engine/SocketEnginePollable.swift b/Source/SocketIO/Engine/SocketEnginePollable.swift index 16db822f..9e55bd99 100644 --- a/Source/SocketIO/Engine/SocketEnginePollable.swift +++ b/Source/SocketIO/Engine/SocketEnginePollable.swift @@ -65,7 +65,7 @@ public protocol SocketEnginePollable : SocketEngineSpec { /// - parameter message: The message to send. /// - parameter withType: The type of message to send. /// - parameter withData: The data associated with this message. - func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping (() -> ())?) + func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (() -> ())?) /// Call to stop polling and invalidate the URLSession. func stopPolling() @@ -219,7 +219,7 @@ extension SocketEnginePollable { /// - parameter withType: The type of message to send. /// - parameter withData: The data associated with this message. /// - parameter completion: Callback called on transport write completion. - public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: @escaping (() -> ())? = nil) { + public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data], completion: (() -> ())? = nil) { DefaultSocketLogger.Logger.log("Sending poll: \(message) as type: \(type.rawValue)", type: "SocketEnginePolling") postWait.append((String(type.rawValue) + message, completion)) diff --git a/Source/SocketIO/Engine/SocketEngineSpec.swift b/Source/SocketIO/Engine/SocketEngineSpec.swift index 52528156..2f01d741 100644 --- a/Source/SocketIO/Engine/SocketEngineSpec.swift +++ b/Source/SocketIO/Engine/SocketEngineSpec.swift @@ -138,7 +138,7 @@ import Starscream /// - parameter type: The type of this message. /// - parameter data: Any data that this message has. /// - parameter completion: Callback called on transport write completion. - func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())?) + func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())?) } extension SocketEngineSpec { @@ -180,7 +180,7 @@ extension SocketEngineSpec { } /// Send an engine message (4) - func send(_ msg: String, withData datas: [Data], completion: @escaping (() -> ())? = nil) { + func send(_ msg: String, withData datas: [Data], completion: (() -> ())? = nil) { write(msg, withType: .message, withData: datas, completion: completion) } } diff --git a/Source/SocketIO/Engine/SocketEngineWebsocket.swift b/Source/SocketIO/Engine/SocketEngineWebsocket.swift index 7fad5bc2..0b85ce13 100644 --- a/Source/SocketIO/Engine/SocketEngineWebsocket.swift +++ b/Source/SocketIO/Engine/SocketEngineWebsocket.swift @@ -41,7 +41,7 @@ public protocol SocketEngineWebsocket : SocketEngineSpec { func sendWebSocketMessage(_ str: String, withType type: SocketEnginePacketType, withData datas: [Data], - completion: @escaping (() -> ())?) + completion: (() -> ())?) } // WebSocket methods @@ -63,7 +63,7 @@ extension SocketEngineWebsocket { public func sendWebSocketMessage(_ str: String, withType type: SocketEnginePacketType, withData datas: [Data], - completion: @escaping (() -> ())? + completion: (() -> ())? ) { DefaultSocketLogger.Logger.log("Sending ws: \(str) as type: \(type.rawValue)", type: "SocketEngineWebSocket") diff --git a/Tests/TestSocketIO/SocketMangerTest.swift b/Tests/TestSocketIO/SocketMangerTest.swift index 9ac3c408..80419482 100644 --- a/Tests/TestSocketIO/SocketMangerTest.swift +++ b/Tests/TestSocketIO/SocketMangerTest.swift @@ -198,7 +198,7 @@ public class TestSocket : SocketIOClient { super.didDisconnect(reason: reason) } - public override func emit(_ event: String, with items: [Any], completion: @escaping (() -> ())?) { + public override func emit(_ event: String, with items: [Any], completion: (() -> ())?) { expectations[ManagerExpectation.emitAllEventCalled]?.fulfill() expectations[ManagerExpectation.emitAllEventCalled] = nil diff --git a/Tests/TestSocketIO/SocketSideEffectTest.swift b/Tests/TestSocketIO/SocketSideEffectTest.swift index 8f1bef9e..a37f198a 100644 --- a/Tests/TestSocketIO/SocketSideEffectTest.swift +++ b/Tests/TestSocketIO/SocketSideEffectTest.swift @@ -511,5 +511,5 @@ class TestEngine : SocketEngineSpec { func flushWaitingForPostToWebSocket() { } func parseEngineData(_ data: Data) { } func parseEngineMessage(_ message: String) { } - func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: @escaping (() -> ())?) { } + func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())?) { } } From e0cbe59a102ffeb5697d1eff21ae4cd3d68ec023 Mon Sep 17 00:00:00 2001 From: Valentin Slawicek Date: Wed, 7 Nov 2018 13:53:25 +0100 Subject: [PATCH 3/3] Remove unnecessary function calls. --- Source/SocketIO/Client/SocketIOClient.swift | 20 +------------------ .../SocketIO/Client/SocketIOClientSpec.swift | 11 +--------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index ef83bcdd..b05b0ecb 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -204,25 +204,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec { leaveNamespace() } - /// Send an event to the server, with optional data items. - /// - /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` - /// will be emitted. The structure of the error data is `[eventName, items, theError]` - /// - /// - parameter event: The event to send. - /// - parameter items: The items to send with this event. May be left out. - open func emit(_ event: String, _ items: SocketData...) { - do { - try emit(event, with: items.map({ try $0.socketRepresentation() })) - } catch { - DefaultSocketLogger.Logger.error("Error creating socketRepresentation for emit: \(event), \(items)", - type: logType) - - handleClientEvent(.error, data: [event, items, error]) - } - } - - /// Send an event to the server, with optional data items and write completion handler. + /// Send an event to the server, with optional data items and optional write completion handler. /// /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` /// will be emitted. The structure of the error data is `[eventName, items, theError]` diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index f2658a8c..17cee736 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -92,16 +92,7 @@ public protocol SocketIOClientSpec : AnyObject { /// Disconnects the socket. func disconnect() - /// Send an event to the server, with optional data items. - /// - /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` - /// will be emitted. The structure of the error data is `[eventName, items, theError]` - /// - /// - parameter event: The event to send. - /// - parameter items: The items to send with this event. May be left out. - func emit(_ event: String, _ items: SocketData...) - - /// Send an event to the server, with optional data items and write completion handler. + /// Send an event to the server, with optional data items and optional write completion handler. /// /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` /// will be emitted. The structure of the error data is `[eventName, items, theError]`