diff --git a/Sources/Engine/NativeEngine.swift b/Sources/Engine/NativeEngine.swift index a1cb4a45..066221b0 100644 --- a/Sources/Engine/NativeEngine.swift +++ b/Sources/Engine/NativeEngine.swift @@ -25,6 +25,7 @@ import Foundation @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) public class NativeEngine: NSObject, Engine, URLSessionDataDelegate, URLSessionWebSocketDelegate { private var task: URLSessionWebSocketTask? + private var session: URLSession? weak var delegate: EngineDelegate? public func register(delegate: EngineDelegate) { @@ -32,8 +33,10 @@ public class NativeEngine: NSObject, Engine, URLSessionDataDelegate, URLSessionW } public func start(request: URLRequest) { - let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil) - task = session.webSocketTask(with: request) + if session == nil { + session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil) + } + task = session?.webSocketTask(with: request) doRead() task?.resume() }