From 28cc8eef192129805e59efd34b022db9b2be1c98 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 13:32:44 -0400 Subject: [PATCH] Don't set configs after connect --- Source/SocketIO/Client/SocketIOClient.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 54ff64e..5ef4f56 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -54,18 +54,24 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// /// **This cannot be set after calling one of the connect methods**. public var config: SocketIOClientConfiguration { - didSet { + get { + return _config + } + + set { guard status == .notConnected else { DefaultSocketLogger.Logger.error("Tried setting config after calling connect", type: SocketIOClient.logType) return } + _config = newValue + if socketURL.absoluteString.hasPrefix("https://") { - config.insert(.secure(true)) + _config.insert(.secure(true)) } - config.insert(.path("/socket.io/"), replacing: false) + _config.insert(.path("/socket.io/"), replacing: false) setConfigs() } } @@ -130,6 +136,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So private(set) var currentAck = -1 private(set) var reconnectAttempts = -1 + private var _config: SocketIOClientConfiguration private var currentReconnectAttempt = 0 private var reconnecting = false @@ -140,14 +147,14 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// - parameter socketURL: The url of the socket.io server. /// - parameter config: The config for this socket. public init(socketURL: URL, config: SocketIOClientConfiguration = []) { - self.config = config + self._config = config self.socketURL = socketURL if socketURL.absoluteString.hasPrefix("https://") { - self.config.insert(.secure(true)) + self._config.insert(.secure(true)) } - self.config.insert(.path("/socket.io/"), replacing: false) + self._config.insert(.path("/socket.io/"), replacing: false) super.init()