@@ -184,10 +184,8 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
184
184
185
185
guard timeoutAfter != 0 else { return }
186
186
187
- let time = DispatchTime . now ( ) + Double( UInt64 ( timeoutAfter) * NSEC_PER_SEC) / Double( NSEC_PER_SEC)
188
-
189
- handleQueue. asyncAfter ( deadline: time) { [ weak self] in
190
- guard let this = self , this. status != . connected && this. status != . disconnected else { return }
187
+ handleQueue. asyncAfter ( deadline: DispatchTime . now ( ) + Double( timeoutAfter) ) { [ weak self] in
188
+ guard let this = self , this. status == . connecting || this. status == . notConnected else { return }
191
189
192
190
this. status = . disconnected
193
191
this. engine? . disconnect ( reason: " Connect timeout " )
@@ -232,13 +230,19 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
232
230
233
231
/// Send an event to the server, with optional data items.
234
232
///
233
+ /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
234
+ /// will be emitted. The structure of the error data is `[eventName, items, theError]`
235
+ ///
235
236
/// - parameter event: The event to send.
236
237
/// - parameter items: The items to send with this event. May be left out.
237
238
open func emit( _ event: String , _ items: SocketData ... ) {
238
239
do {
239
240
emit ( event, with: try items. map ( { try $0. socketRepresentation ( ) } ) )
240
- } catch {
241
- fatalError ( " Error creating socketRepresentation for emit: \( event) , \( items) " )
241
+ } catch let err {
242
+ DefaultSocketLogger . Logger. error ( " Error creating socketRepresentation for emit: \( event) , \( items) " ,
243
+ type: logType)
244
+
245
+ handleClientEvent ( . error, data: [ event, items, err] )
242
246
}
243
247
}
244
248
@@ -260,6 +264,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
260
264
/// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack.
261
265
/// Check that your server's api will ack the event being sent.
262
266
///
267
+ /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
268
+ /// will be emitted. The structure of the error data is `[eventName, items, theError]`
269
+ ///
263
270
/// Example:
264
271
///
265
272
/// ```swift
@@ -274,8 +281,13 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
274
281
open func emitWithAck( _ event: String , _ items: SocketData ... ) -> OnAckCallback {
275
282
do {
276
283
return emitWithAck ( event, with: try items. map ( { try $0. socketRepresentation ( ) } ) )
277
- } catch {
278
- fatalError ( " Error creating socketRepresentation for emit: \( event) , \( items) " )
284
+ } catch let err {
285
+ DefaultSocketLogger . Logger. error ( " Error creating socketRepresentation for emit: \( event) , \( items) " ,
286
+ type: logType)
287
+
288
+ handleClientEvent ( . error, data: [ event, items, err] )
289
+
290
+ return OnAckCallback ( ackNumber: - 1 , items: [ ] , socket: self )
279
291
}
280
292
}
281
293
@@ -426,7 +438,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
426
438
427
439
/// Removes handler(s) based on an event name.
428
440
///
429
- /// If you wish to remove a specific event, call the `off(if :)` with the UUID received from its `on` call.
441
+ /// If you wish to remove a specific event, call the `off(id :)` with the UUID received from its `on` call.
430
442
///
431
443
/// - parameter event: The event to remove handlers for.
432
444
open func off( _ event: String ) {
@@ -555,9 +567,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
555
567
}
556
568
557
569
private func _tryReconnect( ) {
558
- guard reconnecting else { return }
570
+ guard reconnects && reconnecting && status != . disconnected else { return }
559
571
560
- if reconnectAttempts != - 1 && currentReconnectAttempt + 1 > reconnectAttempts || !reconnects {
572
+ if reconnectAttempts != - 1 && currentReconnectAttempt + 1 > reconnectAttempts {
561
573
return didDisconnect ( reason: " Reconnect Failed " )
562
574
}
563
575
0 commit comments