diff --git a/Source/WebSocket.swift b/Source/WebSocket.swift index a6dcbb01..200dc920 100644 --- a/Source/WebSocket.swift +++ b/Source/WebSocket.swift @@ -203,6 +203,7 @@ open class WebSocket : NSObject, StreamDelegate { - Parameter closeCode: The code to send on disconnect. The default is the normal close code for cleanly disconnecting a webSocket. */ open func disconnect(forceTimeout: TimeInterval? = nil, closeCode: UInt16 = CloseCode.normal.rawValue) { + guard isConnected else { return } switch forceTimeout { case .some(let seconds) where seconds > 0: let milliseconds = Int(seconds * 1_000)