Skip to content

Commit af5ce97

Browse files
committed
Merge branch 'development'
* development: handle version in keyValueToSocketIOClientOption Updated methods signature Added client emit methods with array parameters
2 parents 6b80f75 + 2c78e36 commit af5ce97

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

Socket.IO-Client-Swift.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Socket.IO-Client-Swift"
33
s.module_name = "SocketIO"
4-
s.version = "16.0.0"
4+
s.version = "16.0.1"
55
s.summary = "Socket.IO-client for iOS and OS X"
66
s.description = <<-DESC
77
Socket.IO-client for iOS and OS X.
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
s.requires_arc = true
1919
s.source = {
2020
:git => "https://github.com/socketio/socket.io-client-swift.git",
21-
:tag => 'v16.0.0',
21+
:tag => 'v16.0.1',
2222
:submodules => true
2323
}
2424

Source/SocketIO/Client/SocketIOClient.swift

+37
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
212212
/// - parameter items: The items to send with this event. May be left out.
213213
/// - parameter completion: Callback called on transport write completion.
214214
open func emit(_ event: String, _ items: SocketData..., completion: (() -> ())? = nil) {
215+
emit(event, with: items, completion: completion)
216+
}
217+
218+
/// Send an event to the server, with optional data items and optional write completion handler.
219+
///
220+
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
221+
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
222+
///
223+
/// - parameter event: The event to send.
224+
/// - parameter items: The items to send with this event. May be left out.
225+
/// - parameter completion: Callback called on transport write completion.
226+
open func emit(_ event: String, with items: [SocketData], completion: (() -> ())?) {
227+
215228
do {
216229
emit([event] + (try items.map({ try $0.socketRepresentation() })), completion: completion)
217230
} catch {
@@ -242,6 +255,30 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
242255
/// - parameter items: The items to send with this event. May be left out.
243256
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
244257
open func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback {
258+
emitWithAck(event, with: items)
259+
}
260+
261+
/// Sends a message to the server, requesting an ack.
262+
///
263+
/// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack.
264+
/// Check that your server's api will ack the event being sent.
265+
///
266+
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
267+
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
268+
///
269+
/// Example:
270+
///
271+
/// ```swift
272+
/// socket.emitWithAck("myEvent", 1).timingOut(after: 1) {data in
273+
/// ...
274+
/// }
275+
/// ```
276+
///
277+
/// - parameter event: The event to send.
278+
/// - parameter items: The items to send with this event. May be left out.
279+
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
280+
open func emitWithAck(_ event: String, with items: [SocketData]) -> OnAckCallback {
281+
245282
do {
246283
return createOnAck([event] + (try items.map({ try $0.socketRepresentation() })))
247284
} catch {

Source/SocketIO/Client/SocketIOClientSpec.swift

+31
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public protocol SocketIOClientSpec : AnyObject {
107107
/// - parameter items: The items to send with this event. May be left out.
108108
/// - parameter completion: Callback called on transport write completion.
109109
func emit(_ event: String, _ items: SocketData..., completion: (() -> ())?)
110+
111+
/// Send an event to the server, with optional data items and optional write completion handler.
112+
///
113+
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
114+
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
115+
///
116+
/// - parameter event: The event to send.
117+
/// - parameter items: The items to send with this event. May be left out.
118+
/// - parameter completion: Callback called on transport write completion.
119+
func emit(_ event: String, with items: [SocketData], completion: (() -> ())?)
110120

111121
/// Call when you wish to tell the server that you've received the event for `ack`.
112122
///
@@ -134,6 +144,27 @@ public protocol SocketIOClientSpec : AnyObject {
134144
/// - parameter items: The items to send with this event. May be left out.
135145
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
136146
func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback
147+
148+
/// Sends a message to the server, requesting an ack.
149+
///
150+
/// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack.
151+
/// Check that your server's api will ack the event being sent.
152+
///
153+
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
154+
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
155+
///
156+
/// Example:
157+
///
158+
/// ```swift
159+
/// socket.emitWithAck("myEvent", 1).timingOut(after: 1) {data in
160+
/// ...
161+
/// }
162+
/// ```
163+
///
164+
/// - parameter event: The event to send.
165+
/// - parameter items: The items to send with this event. May be left out.
166+
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
167+
func emitWithAck(_ event: String, with items: [SocketData]) -> OnAckCallback
137168

138169
/// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called.
139170
///

Source/SocketIO/Util/SocketExtensions.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ extension Dictionary where Key == String, Value == Any {
8787
return compress ? .compress : nil
8888
case let ("enableSOCKSProxy", enable as Bool):
8989
return .enableSOCKSProxy(enable)
90-
default:
90+
case let ("version", version as Int):
91+
return .version(SocketIOVersion(rawValue: version) ?? .three)
92+
case _:
9193
return nil
9294
}
9395
}

0 commit comments

Comments
 (0)