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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user