Emit parameters wrapped twice
Hello! Found an issue with your code emit methods syntax, which breaks the use of it if wrapped in another method. Take for example a simple emit:
open func emit(_ event: String, _ items: SocketData..., completion: (() -> ())? = nil) {
do {
emit([event] + (try items.map({ try $0.socketRepresentation() })), completion: completion)
} catch {
DefaultSocketLogger.Logger.error("Error creating socketRepresentation for emit: \(event), \(items)",
type: logType)
handleClientEvent(.error, data: [event, items, error])
}
}
You make use of variadic parameter, which is totally fine when used directly. For example socket.emit(event, arg1, arg2)
But if you wrap the call to this method:
func send(event: String, with arguments: [SocketTransferable]) {
socket.emit(event, arguments)
}
the call send(event, arguments) will result in arguments being wrapped in array again because of how variadic parameters work. I can even write my method like this
func send(event: String, with arguments: SocketTransferable...) {
socket.emit(event, arguments)
}
and still get errors from server for calls like send(event, arg1, arg2).
A great idea will be to have an overload that accepts array. Like old obj-c methods that were removed
@nuclearace I created PR (https://github.com/socketio/socket.io-client-swift/pull/1324) wit proposed changes