-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Description
What are you trying to achieve?
I am trying to call all members of team red. Currently, there is no good way to do that.
There exists a https://chat.stream-io-api.com/api/v2/users API on the StreamVideo backend, but there is no call to easily access it from the SDK.
If possible, how can you achieve this currently?
// Fetch members for a team
private func getMembersForTeam(teamName: String) async throws -> [String] {
guard let streamVideo = streamVideo else {
throw NSError(domain: "StreamCallPlugin", code: -1, userInfo: [NSLocalizedDescriptionKey: "StreamVideo not initialized"])
}
guard let credentials = SecureUserRepository.shared.loadCurrentUser() else {
throw NSError(domain: "StreamCallPlugin", code: -1, userInfo: [NSLocalizedDescriptionKey: "Credentials not found"])
}
// Create URL for the Stream Chat API
var urlComponents = URLComponents(string: "https://chat.stream-io-api.com/api/v2/users")!
// Create the filter payload
let filterPayload: [String: Any] = [
"filter_conditions": [
"teams": [
"$in": [teamName]
]
]
]
// Convert payload to JSON string
let jsonData = try JSONSerialization.data(withJSONObject: filterPayload)
let jsonString = String(data: jsonData, encoding: .utf8)!
// Add payload as query parameter
urlComponents.queryItems = [URLQueryItem(name: "payload", value: jsonString)]
// Create URL request
var request = URLRequest(url: urlComponents.url!)
request.httpMethod = "GET"
request.addValue("Bearer \(credentials.tokenValue)", forHTTPHeaderField: "Authorization")
// Perform the request
let (data, response) = try await URLSession.shared.data(for: request)
// Check response status
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
throw NSError(domain: "StreamCallPlugin", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to fetch team members"])
}
// Parse the response
let responseObject = try JSONSerialization.jsonObject(with: data) as? [String: Any]
guard let users = responseObject?["users"] as? [[String: Any]] else {
throw NSError(domain: "StreamCallPlugin", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid response format"])
}
// Extract user IDs
let memberIds = users.compactMap { $0["id"] as? String }
return memberIds
}What would be the better way?
Get a proper SDK to do this
GetStream Environment
**GetStream Video version: 1.16.0
GetStream Video frameworks: StreamVideo, StreamVideoSwiftUI
iOS version: 18.4
Swift version:
> swift --version
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: x86_64-apple-macosx15.0
Xcode version: Version 16.2 (16C5032a)
Device: iPad pro (12.9-inch) (5th generation)
Metadata
Metadata
Assignees
Labels
No labels