Skip to content

Commit 18ae5bd

Browse files
committed
Remove transient disconnect handling from Connection.
1 parent ff4b8b4 commit 18ae5bd

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

Sources/AblyChat/DefaultConnection.swift

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Ably
22

33
internal final class DefaultConnection: Connection {
44
private let realtime: any InternalRealtimeClientProtocol
5-
private let timerManager = TimerManager(clock: SystemClock())
65

76
// (CHA-CS2a) The chat client must expose its current connection status.
87
internal var status: ConnectionStatus {
@@ -24,7 +23,7 @@ internal final class DefaultConnection: Connection {
2423
internal func onStatusChange(_ callback: @escaping @MainActor (ConnectionStatusChange) -> Void) -> some StatusSubscription {
2524
// (CHA-CS5) The chat client must monitor the underlying realtime connection for connection status changes.
2625
let eventListener = realtime.connection.on { [weak self] stateChange in
27-
guard let self else {
26+
guard self != nil else {
2827
return
2928
}
3029
let currentState = ConnectionStatus.fromRealtimeConnectionState(stateChange.current)
@@ -41,43 +40,14 @@ internal final class DefaultConnection: Connection {
4140
retryIn: stateChange.retryIn,
4241
)
4342

44-
let isTimerRunning = timerManager.hasRunningTask()
45-
// (CHA-CS5a) The chat client must suppress transient disconnection events. It is not uncommon for Ably servers to perform connection shedding to balance load, or due to retiring. Clients should not need to concern themselves with transient events.
46-
47-
// (CHA-CS5a2) If a transient disconnect timer is active and the realtime connection status changes to `DISCONNECTED` or `CONNECTING`, the library must not emit a status change.
48-
if isTimerRunning, currentState == .disconnected || currentState == .connecting {
49-
return
50-
}
51-
52-
// (CHA-CS5a3) If a transient disconnect timer is active and the realtime connections status changes to `CONNECTED`, `SUSPENDED` or `FAILED`, the library shall cancel the transient disconnect timer. The superseding status change shall be emitted.
53-
if isTimerRunning, currentState == .connected || currentState == .suspended || currentState == .failed {
54-
timerManager.cancelTimer()
55-
callback(statusChange)
56-
}
57-
58-
// (CHA-CS5a1) If the realtime connection status transitions from `CONNECTED` to `DISCONNECTED`, the chat client connection status must not change. A 5 second transient disconnect timer shall be started.
59-
if previousState == .connected, currentState == .disconnected, !isTimerRunning {
60-
timerManager.setTimer(interval: 5.0) { [timerManager] in
61-
// (CHA-CS5a4) If a transient disconnect timer expires the library shall emit a connection status change event. This event must contain the current status of of timer expiry, along with the original error that initiated the transient disconnect timer.
62-
timerManager.cancelTimer()
63-
callback(statusChange)
64-
}
65-
return
66-
}
67-
68-
if isTimerRunning {
69-
timerManager.cancelTimer()
70-
}
71-
72-
// (CHA-CS5b) Not withstanding CHA-CS5a. If a connection state event is observed from the underlying realtime library, the client must emit a status change event. The current status of that event shall reflect the status change in the underlying realtime library, along with the accompanying error.
43+
// (CHA-CS5c) The current status of that event shall reflect the status change in the underlying realtime library, along with the accompanying error.
7344
callback(statusChange)
7445
}
7546

7647
return DefaultStatusSubscription { [weak self] in
7748
guard let self else {
7849
return
7950
}
80-
timerManager.cancelTimer()
8151
realtime.connection.off(eventListener)
8252
}
8353
}

0 commit comments

Comments
 (0)