Skip to content

Commit 435b675

Browse files
committed
Fix WS front wiring and AppDelegate keepalive task
- MTWebSocketConnectionInterface: use WebSocketFrontBootstrap.templates as default plan config so CF Worker fronts are picked up without SharedData round-trip - AppDelegate: replace mutable-closure keepalive pattern with Box class to avoid variable-capture issue with UIBackgroundTaskIdentifier Co-authored-by: D3C0Y <decoder-dev@users.noreply.github.com>
1 parent a8e51df commit 435b675

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎submodules/TelegramCore/Sources/Network/MTWebSocketConnectionInterface.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ final class MTWebSocketConnectionInterface: NSObject, MTTcpConnectionInterface {
263263
self.isMediaConnection = isMediaConnection
264264
self.isTestingEnvironment = isTestingEnvironment
265265
self.fallbackCoordinator = fallbackCoordinator
266+
let frontConfig = WebSocketEndpointPlanConfig(fronts: WebSocketFrontBootstrap.templates, order: .frontsFirst)
266267
self.endpointSelector = WebSocketEndpointSelector(candidates: WebSocketEndpointPlanner.candidates(
267268
datacenterId: datacenterId,
268269
isMedia: isMediaConnection,
269-
isTestingEnvironment: isTestingEnvironment
270+
isTestingEnvironment: isTestingEnvironment,
271+
config: frontConfig
270272
))
271273
}
272274

‎submodules/TelegramUI/Sources/AppDelegate.swift‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,16 +2086,20 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
20862086
// Keep the WEB proxy carrier alive briefly in the background so the next foreground
20872087
// resume can skip the carrier rebuild (avoids "Connecting" flicker). A single PING is
20882088
// enough — the relay's own keep-alive timer runs on the server side.
2089-
var webProxyKeepaliveTaskId = UIBackgroundTaskIdentifier.invalid
2090-
let endWebProxyKeepaliveTask = { [application] in
2091-
let id = webProxyKeepaliveTaskId
2092-
webProxyKeepaliveTaskId = .invalid
2093-
if id != .invalid { application.endBackgroundTask(id) }
2094-
}
2095-
webProxyKeepaliveTaskId = application.beginBackgroundTask(withName: "web-proxy-keepalive", expirationHandler: endWebProxyKeepaliveTask)
2096-
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
2089+
final class Box { var value: UIBackgroundTaskIdentifier = .invalid }
2090+
let webProxyTaskBox = Box()
2091+
webProxyTaskBox.value = application.beginBackgroundTask(withName: "web-proxy-keepalive") { [weak webProxyTaskBox] in
2092+
if let box = webProxyTaskBox, box.value != .invalid {
2093+
application.endBackgroundTask(box.value)
2094+
box.value = .invalid
2095+
}
2096+
}
2097+
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [weak webProxyTaskBox] in
20972098
let _ = WebProxyManager.shared.sendKeepalivePing()
2098-
endWebProxyKeepaliveTask()
2099+
if let box = webProxyTaskBox, box.value != .invalid {
2100+
application.endBackgroundTask(box.value)
2101+
box.value = .invalid
2102+
}
20992103
}
21002104
}
21012105

0 commit comments

Comments
 (0)