     // MARK: - WebSocketConnection conformance
 
     func connect() {
-        webSocketTask.resume()
+        if webSocketTask == nil {
+            webSocketTask = urlSession.webSocketTask(with: webSocketRequest)
+        }
+
+        webSocketTask?.resume()
         listen()
     }
 


    // MARK: - Private properties

    private var webSocketTask: URLSessionWebSocketTask!
    private var urlSession: URLSession!
    private let delegateQueue = OperationQueue()
    private var pingTimer: Timer?

    }

    func listen() {
        webSocketTask?.receive { [weak self] result in
            guard let self = self else {
                return
            }
