Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Last active September 26, 2023 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/6cd5775e02aea1cbcbcd43f81d999ba1 to your computer and use it in GitHub Desktop.
Save amosgyamfi/6cd5775e02aea1cbcbcd43f81d999ba1 to your computer and use it in GitHub Desktop.
import SwiftUI
import StreamVideo
import StreamVideoSwiftUI
struct VideoClientSetUp: View {
@State var call: Call
@ObservedObject var state: CallState
@State var callCreated: Bool = false
private var client: StreamVideo
private let apiKey: String = "" // The API key can be found in the Credentials section
private let userId: String = "REPLACE_WITH_USER_ID" // The User Id can be found in the Credentials section
private let token: String = "REPLACE_WITH_TOKEN" // The Token can be found in the Credentials section
private let callId: String = "REPLACE_WITH_CALL_ID" // The CallId can be found in the Credentials section
init() {
let user = User(
id: userId,
name: "Martin", // name and imageURL are used in the UI
imageURL: .init(string: "https://getstream.io/static/2796a305dd07651fcceb4721a94f4505/a3911/martin-mitrevski.webp")
)
// Initialize Stream Video client
self.client = StreamVideo(
apiKey: apiKey,
user: user,
token: .init(stringLiteral: token)
)
// Initialize the call object
let call = client.call(callType: "default", callId: callId)
self.call = call
self.state = call.state
}
var body: some View {
VStack {
if callCreated {
Text("Meeting Call \(call.callId) has \(call.state.participants.count) participant")
.font(.system(size: 30))
.foregroundColor(.blue)
} else {
VStack {
ProgressView()
Text("loading...")
}
}
}.onAppear {
Task {
guard !callCreated else { return }
try await call.join(create: true)
callCreated = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment