From c01501278349beeffda58877a4e0c784b523daf6 Mon Sep 17 00:00:00 2001 From: Erasov Ivan Date: Fri, 5 Feb 2021 19:14:54 +0300 Subject: [PATCH 1/3] Added client emit methods with array parameters --- Source/SocketIO/Client/SocketIOClient.swift | 37 +++++++++++++++++++ .../SocketIO/Client/SocketIOClientSpec.swift | 31 ++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 160d2e9a..2f0c6cff 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -212,6 +212,19 @@ open class SocketIOClient: NSObject, SocketIOClientSpec { /// - 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: (() -> ())? = nil) { + emit(event, items, completion: completion) + } + + /// 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]` + /// + /// - 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: (() -> ())?) { + do { emit([event] + (try items.map({ try $0.socketRepresentation() })), completion: completion) } catch { @@ -242,6 +255,30 @@ open class SocketIOClient: NSObject, SocketIOClientSpec { /// - parameter items: The items to send with this event. May be left out. /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. open func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback { + emitWithAck(event, items) + } + + /// Sends a message to the server, requesting an ack. + /// + /// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack. + /// Check that your server's api will ack the event being sent. + /// + /// 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]` + /// + /// Example: + /// + /// ```swift + /// socket.emitWithAck("myEvent", 1).timingOut(after: 1) {data in + /// ... + /// } + /// ``` + /// + /// - parameter event: The event to send. + /// - parameter items: The items to send with this event. May be left out. + /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. + open func emitWithAck(_ event: String, _ items: [SocketData]) -> OnAckCallback { + do { return createOnAck([event] + (try items.map({ try $0.socketRepresentation() }))) } catch { diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index 9c0e5504..a0298c36 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -107,6 +107,16 @@ public protocol SocketIOClientSpec : AnyObject { /// - 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: (() -> ())?) + + /// 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]` + /// + /// - 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: (() -> ())?) /// Call when you wish to tell the server that you've received the event for `ack`. /// @@ -134,6 +144,27 @@ public protocol SocketIOClientSpec : AnyObject { /// - parameter items: The items to send with this event. May be left out. /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback + + /// Sends a message to the server, requesting an ack. + /// + /// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack. + /// Check that your server's api will ack the event being sent. + /// + /// 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]` + /// + /// Example: + /// + /// ```swift + /// socket.emitWithAck("myEvent", 1).timingOut(after: 1) {data in + /// ... + /// } + /// ``` + /// + /// - parameter event: The event to send. + /// - parameter items: The items to send with this event. May be left out. + /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. + func emitWithAck(_ event: String, _ items: [SocketData]) -> OnAckCallback /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. /// From ef6b63c82fa2e1da850619f4f12f39a677d36fea Mon Sep 17 00:00:00 2001 From: Erasov Ivan Date: Tue, 9 Feb 2021 00:13:42 +0300 Subject: [PATCH 2/3] Updated methods signature --- Source/SocketIO/Client/SocketIOClient.swift | 8 ++++---- Source/SocketIO/Client/SocketIOClientSpec.swift | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 2f0c6cff..4debd560 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -212,7 +212,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec { /// - 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: (() -> ())? = nil) { - emit(event, items, completion: completion) + emit(event, with: items, completion: completion) } /// Send an event to the server, with optional data items and optional write completion handler. @@ -223,7 +223,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: (() -> ())?) { + open func emit(_ event: String, with items: [SocketData], completion: (() -> ())?) { do { emit([event] + (try items.map({ try $0.socketRepresentation() })), completion: completion) @@ -255,7 +255,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec { /// - parameter items: The items to send with this event. May be left out. /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. open func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback { - emitWithAck(event, items) + emitWithAck(event, with: items) } /// Sends a message to the server, requesting an ack. @@ -277,7 +277,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. /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. - open func emitWithAck(_ event: String, _ items: [SocketData]) -> OnAckCallback { + open func emitWithAck(_ event: String, with items: [SocketData]) -> OnAckCallback { do { return createOnAck([event] + (try items.map({ try $0.socketRepresentation() }))) diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index a0298c36..04b62faa 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -116,7 +116,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: (() -> ())?) + func emit(_ event: String, with items: [SocketData], completion: (() -> ())?) /// Call when you wish to tell the server that you've received the event for `ack`. /// @@ -164,7 +164,7 @@ public protocol SocketIOClientSpec : AnyObject { /// - parameter event: The event to send. /// - parameter items: The items to send with this event. May be left out. /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. - func emitWithAck(_ event: String, _ items: [SocketData]) -> OnAckCallback + func emitWithAck(_ event: String, with items: [SocketData]) -> OnAckCallback /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. /// From 2c78e36ebdc368fa303f7d299cc520da571bec7c Mon Sep 17 00:00:00 2001 From: Erik Little Date: Tue, 16 Feb 2021 09:35:11 -0500 Subject: [PATCH 3/3] handle version in keyValueToSocketIOClientOption --- Socket.IO-Client-Swift.podspec | 4 ++-- Source/SocketIO/Util/SocketExtensions.swift | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 50a988e1..60e68527 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Socket.IO-Client-Swift" s.module_name = "SocketIO" - s.version = "16.0.0" + s.version = "16.0.1" s.summary = "Socket.IO-client for iOS and OS X" s.description = <<-DESC Socket.IO-client for iOS and OS X. @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", - :tag => 'v16.0.0', + :tag => 'v16.0.1', :submodules => true } diff --git a/Source/SocketIO/Util/SocketExtensions.swift b/Source/SocketIO/Util/SocketExtensions.swift index 63b0b99d..d44ea26d 100644 --- a/Source/SocketIO/Util/SocketExtensions.swift +++ b/Source/SocketIO/Util/SocketExtensions.swift @@ -87,7 +87,9 @@ extension Dictionary where Key == String, Value == Any { return compress ? .compress : nil case let ("enableSOCKSProxy", enable as Bool): return .enableSOCKSProxy(enable) - default: + case let ("version", version as Int): + return .version(SocketIOVersion(rawValue: version) ?? .three) + case _: return nil } }