Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flw 1905 random crash #80

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion FearlessUtils/Classes/Network/JSONRPCEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public final class JSONRPCSubscription<T: Decodable>: JSONRPCSubscribing {
}

public protocol JSONRPCEngine: AnyObject {
var pendingEngineRequests: [JSONRPCRequest] { get }

func callMethod<P: Encodable, T: Decodable>(
_ method: String,
params: P?,
Expand All @@ -114,7 +116,7 @@ public protocol JSONRPCEngine: AnyObject {

func generateRequestId() -> UInt16
func addSubscription(_ subscription: JSONRPCSubscribing)
func reconnect(url: URL)
func connect(with pendingRequests: [JSONRPCRequest])
}

public extension JSONRPCEngine {
Expand Down
28 changes: 8 additions & 20 deletions FearlessUtils/Classes/Network/WebSocketEngine+Protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import Foundation
import Starscream

extension WebSocketEngine: JSONRPCEngine {
public var pendingEngineRequests: [JSONRPCRequest] {
self.pendingRequests
}

public func callMethod<P: Encodable, T: Decodable>(
_ method: String,
params: P?,
Expand Down Expand Up @@ -70,25 +74,9 @@ extension WebSocketEngine: JSONRPCEngine {
mutex.unlock()
}

public func reconnect(url: URL) {
self.connection.delegate = nil
self.disconnectIfNeeded()

self.url = url
let request = URLRequest(url: url, timeoutInterval: 10)

let engine = WSEngine(
transport: FoundationTransport(),
certPinner: FoundationSecurity(),
compressionHandler: nil
)

let connection = WebSocket(request: request, engine: engine)
self.connection = connection

connection.callbackQueue = Self.sharedProcessingQueue
connection.delegate = self

self.connectIfNeeded()
public func connect(with pendingRequests: [JSONRPCRequest]) {
pendingRequests.forEach {
updateConnectionForRequest($0)
}
}
}
3 changes: 3 additions & 0 deletions FearlessUtils/Classes/Network/WebSocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public final class WebSocketEngine {

public weak var delegate: WebSocketEngineDelegate?
public var url: URL?
public var connectionName: String?

public init(
connectionName: String?,
url: URL,
reachabilityManager: ReachabilityManagerProtocol? = nil,
reconnectionStrategy: ReconnectionStrategyProtocol? = ExponentialReconnection(),
Expand All @@ -80,6 +82,7 @@ public final class WebSocketEngine {
pingInterval: TimeInterval = 30,
logger: SDKLoggerProtocol? = nil
) {
self.connectionName = connectionName
self.url = url
self.version = version
self.logger = logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public extension TypeRegistryCatalog {
_ definitionData: Data,
versionedJsons: [UInt64: JSON],
runtimeMetadata: RuntimeMetadata,
customNodes: [Node],
customNodes: [Node] = [],
usedRuntimePaths: [String: [String]]
) throws -> TypeRegistryCatalog {
let additonalNodes = BasisNodes.allNodes(for: runtimeMetadata) + customNodes
Expand Down