     }
 
     func ping() {
-        self.webSocketTask.sendPing { error in
+        self.webSocketTask?.sendPing { error in
             if let error = error {
                 self.delegate?.webSocketDidReceiveError(connection: self, error: error)
             } else {

    }

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


    // MARK: - Private properties

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