@@ -79,6 +79,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
79
79
public private( set) var sid : String ?
80
80
81
81
let ackHandlers = SocketAckManager ( )
82
+ var connectPayload : [ String : Any ] ?
82
83
83
84
private( set) var currentAck = - 1
84
85
@@ -107,8 +108,8 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
107
108
/// Connect to the server. The same as calling `connect(timeoutAfter:withHandler:)` with a timeout of 0.
108
109
///
109
110
/// Only call after adding your event listeners, unless you know what you're doing.
110
- open func connect( ) {
111
- connect ( timeoutAfter: 0 , withHandler: nil )
111
+ open func connect( withPayload payload : [ String : Any ] ? = nil ) {
112
+ connect ( withPayload : payload , timeoutAfter: 0 , withHandler: nil )
112
113
}
113
114
114
115
/// Connect to the server. If we aren't connected after `timeoutAfter` seconds, then `withHandler` is called.
@@ -118,7 +119,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
118
119
/// - parameter timeoutAfter: The number of seconds after which if we are not connected we assume the connection
119
120
/// has failed. Pass 0 to never timeout.
120
121
/// - parameter handler: The handler to call when the client fails to connect.
121
- open func connect( timeoutAfter: Double , withHandler handler: ( ( ) -> ( ) ) ? ) {
122
+ open func connect( withPayload payload : [ String : Any ] ? = nil , timeoutAfter: Double , withHandler handler: ( ( ) -> ( ) ) ? ) {
122
123
assert ( timeoutAfter >= 0 , " Invalid timeout: \( timeoutAfter) " )
123
124
124
125
guard let manager = self . manager, status != . connected else {
@@ -128,7 +129,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
128
129
129
130
status = . connecting
130
131
131
- joinNamespace ( )
132
+ joinNamespace ( withPayload : payload )
132
133
133
134
guard timeoutAfter != 0 else { return }
134
135
@@ -340,11 +341,15 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
340
341
manager? . disconnectSocket ( self )
341
342
}
342
343
343
- /// Joins `nsp`.
344
- open func joinNamespace( ) {
344
+ /// Joins `nsp`. You shouldn't need to call this directly, instead call `connect`.
345
+ ///
346
+ /// - Parameter payload: The optional
347
+ open func joinNamespace( withPayload payload: [ String : Any ] ? = nil ) {
345
348
DefaultSocketLogger . Logger. log ( " Joining namespace \( nsp) " , type: logType)
346
349
347
- manager? . connectSocket ( self )
350
+ connectPayload = payload
351
+
352
+ manager? . connectSocket ( self , withPayload: connectPayload)
348
353
}
349
354
350
355
/// Removes handler(s) for a client event.
0 commit comments