feat(ios): add online device list and pairing code redemption

- Add API methods for fetching online devices and redeeming pairing codes
- Add OnlineDevice model and corresponding ViewModel state management
- Add UI sections for online device list and pairing code input in SetupPanel
- Ensure access token is verified before connecting to signaling server
This commit is contained in:
2026-08-03 21:42:31 +08:00
parent da0a3bf59d
commit 1bd0318d35
3 changed files with 179 additions and 7 deletions

View File

@@ -45,12 +45,32 @@ struct ApiClient {
return try await get("/api/client/turn-credentials", accessToken: accessToken)
}
/// 线线
/// Flutter `devices_online`GET /api/client/devices/online
static func onlineDevices(accessToken: String) async throws -> [String: Any] {
return try await get("/api/client/devices/online", accessToken: accessToken)
}
///
/// Flutter `redeemPairingCode`POST /api/client/pairing/redeem
static func redeemPairingCode(accessToken: String, code: String) async throws -> [String: Any] {
let body: [String: Any] = ["code": code]
return try await post("/api/client/pairing/redeem", body: body, accessToken: accessToken)
}
// MARK: - Private
private static func post(_ path: String, body: [String: Any]) async throws -> [String: Any] {
return try await post(path, body: body, accessToken: nil)
}
private static func post(_ path: String, body: [String: Any], accessToken: String?) async throws -> [String: Any] {
var req = URLRequest(url: URL(string: baseURL + path)!)
req.httpMethod = "POST"
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
if let accessToken, !accessToken.isEmpty {
req.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
}
req.httpBody = try JSONSerialization.data(withJSONObject: body)
return try await perform(req)
}