@@ -33,9 +33,6 @@ import Foundation
33
33
open class SocketIOClient : NSObject , SocketIOClientSpec , SocketEngineClient , SocketParsable {
34
34
// MARK: Properties
35
35
36
- /// The URL of the socket.io server. This is set in the initializer.
37
- public let socketURL : URL
38
-
39
36
/// The engine for this client.
40
37
public private( set) var engine : SocketEngineSpec ?
41
38
@@ -78,19 +75,25 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
78
75
return engine? . sid
79
76
}
80
77
78
+ /// The URL of the socket.io server.
79
+ ///
80
+ /// If changed after calling `init`, `forceNew` must be set to `true`, or it will only connect to the url set in the
81
+ /// init.
82
+ public var socketURL : URL
83
+
84
+ var ackHandlers = SocketAckManager ( )
85
+ var waitingPackets = [ SocketPacket] ( )
86
+
87
+ private( set) var currentAck = - 1
88
+ private( set) var reconnectAttempts = - 1
89
+
81
90
private let logType = " SocketIOClient "
82
91
83
92
private var anyHandler : ( ( SocketAnyEvent ) -> Void ) ?
84
93
private var currentReconnectAttempt = 0
85
94
private var handlers = [ SocketEventHandler] ( )
86
95
private var reconnecting = false
87
96
88
- private( set) var currentAck = - 1
89
- private( set) var reconnectAttempts = - 1
90
-
91
- var ackHandlers = SocketAckManager ( )
92
- var waitingPackets = [ SocketPacket] ( )
93
-
94
97
// MARK: Initializers
95
98
96
99
/// Type safe way to create a new SocketIOClient. `opts` can be omitted.
@@ -149,13 +152,11 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
149
152
150
153
// MARK: Methods
151
154
152
- private func addEngine( ) -> SocketEngineSpec {
155
+ private func addEngine( ) {
153
156
DefaultSocketLogger . Logger. log ( " Adding engine " , type: logType, args: " " )
154
157
155
158
engine? . client = nil
156
159
engine = SocketEngine ( client: self , url: socketURL, config: config)
157
-
158
- return engine!
159
160
}
160
161
161
162
/// Connect to the server.
@@ -179,11 +180,11 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So
179
180
status = . connecting
180
181
181
182
if engine == nil || forceNew {
182
- addEngine ( ) . connect ( )
183
- } else {
184
- engine? . connect ( )
183
+ addEngine ( )
185
184
}
186
185
186
+ engine? . connect ( )
187
+
187
188
guard timeoutAfter != 0 else { return }
188
189
189
190
handleQueue. asyncAfter ( deadline: DispatchTime . now ( ) + Double( timeoutAfter) ) { [ weak self] in
0 commit comments