Skip to content

Commit

Permalink
Merge pull request #59 from novasamatech/fix-connection-delegate-on-u…
Browse files Browse the repository at this point in the history
…rl-change

fix connection delegate on url change
  • Loading branch information
svojsu authored Jun 18, 2024
2 parents 44e4fb1 + 7725d76 commit 86b26af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PODS:
- scrypt.c (0.1.1)
- secp256k1.c (0.1.2)
- Starscream (4.0.4)
- SubstrateSdk (3.1.0):
- SubstrateSdk (3.1.1):
- BigInt (~> 5.0)
- IrohaCrypto/ed25519 (~> 0.9.0)
- IrohaCrypto/Scrypt (~> 0.9.0)
Expand Down Expand Up @@ -87,7 +87,7 @@ SPEC CHECKSUMS:
scrypt.c: b42ae06183251329d2b2c620c226fb541a4a3592
secp256k1.c: db47b726585d80f027423682eb369729e61b3b20
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
SubstrateSdk: 9f5fb4e2664b19e171c5600cd511f9d5372bada7
SubstrateSdk: d51ad2eeab63e4603adeb5850bc7c095682fd591
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
Expand Down
2 changes: 1 addition & 1 deletion SubstrateSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SubstrateSdk'
s.version = '3.1.0'
s.version = '3.1.1'
s.summary = 'Utility library that implements clients specific logic to interact with substrate based networks'

s.homepage = 'https://github.com/nova-wallet/substrate-sdk-ios'
Expand Down
21 changes: 11 additions & 10 deletions SubstrateSdk/Classes/Network/WebSocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public protocol WebSocketEngineDelegate: AnyObject {

public final class WebSocketEngine {
public enum State: Equatable {
case notConnected
case connecting
case waitingReconnection
case notConnected(url: URL?)
case connecting(url: URL)
case waitingReconnection(url: URL)
case connected(url: URL)
}

Expand All @@ -43,7 +43,7 @@ public final class WebSocketEngine {
public let pingInterval: TimeInterval
public let connectionTimeout: TimeInterval

public private(set) var state: State = .notConnected {
public private(set) var state: State = .notConnected(url: nil) {
didSet {
if let delegate = delegate {
let oldState = oldValue
Expand Down Expand Up @@ -170,6 +170,7 @@ public final class WebSocketEngine {
processingQueue: self.processingQueue,
connectionTimeout: connectionTimeout
)
connection.delegate = self

logger?.debug("(\(chainName)) Did set new urls: \(newUrls)")

Expand Down Expand Up @@ -204,7 +205,7 @@ public final class WebSocketEngine {

switch state {
case .connected:
state = .notConnected
state = .notConnected(url: selectedURL)

let cancelledRequests = resetInProgress()

Expand All @@ -223,14 +224,14 @@ public final class WebSocketEngine {

logger?.debug("(\(chainName):\(selectedURL)) Did start disconnect from socket")
case .connecting:
state = .notConnected
state = .notConnected(url: selectedURL)

forceConnectionReset()

logger?.debug("(\(chainName):\(selectedURL)) Cancel socket connection")

case .waitingReconnection:
state = .notConnected
state = .notConnected(url: selectedURL)

forceConnectionReset()
reconnectionScheduler.cancel()
Expand Down Expand Up @@ -666,7 +667,7 @@ extension WebSocketEngine {

if let reconnectionStrategy = reconnectionStrategy,
let nextDelay = reconnectionStrategy.reconnectAfter(attempt: actualAttempt) {
state = .waitingReconnection
state = .waitingReconnection(url: selectedURL)

let chainName = "\(chainName):\(selectedURL)"
logger?.debug(
Expand All @@ -675,7 +676,7 @@ extension WebSocketEngine {

reconnectionScheduler.notifyAfter(nextDelay)
} else {
state = .notConnected
state = .notConnected(url: selectedURL)

// notify pendings about error because there is no chance to reconnect

Expand Down Expand Up @@ -789,7 +790,7 @@ extension WebSocketEngine {
logger?.debug("(\(chainName):\(selectedURL)) Start connecting with attempt: \(attempt)")

updateReconnectionAttempts(attempt, for: selectedURL)
state = .connecting
state = .connecting(url: selectedURL)

connection.connect()
}
Expand Down

0 comments on commit 86b26af

Please sign in to comment.