Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created September 13, 2023 11:42
Show Gist options
  • Save amosgyamfi/d2e6558f26c015c252a9b5e951c9cab6 to your computer and use it in GitHub Desktop.
Save amosgyamfi/d2e6558f26c015c252a9b5e951c9cab6 to your computer and use it in GitHub Desktop.
import SwiftUI
import StreamVideo
import StreamVideoSwiftUI
@main
struct BasicAdvancedThemingApp: App {
@ObservedObject var viewModel: CallViewModel
private var client: StreamVideo
private let apiKey: String = "mmhfdzb5evj2" // The API key can be found in the Credentials section
private let userId: String = "Cad_Bane" // The User Id can be found in the Credentials section
private let token: String = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiQ2FkX0JhbmUiLCJpc3MiOiJwcm9udG8iLCJzdWIiOiJ1c2VyL0NhZF9CYW5lIiwiaWF0IjoxNjk0MTcyNTY2LCJleHAiOjE2OTQ3NzczNzF9.6xGFS_XoFzcTlXD7wLx91Xa7H38vpCByXtpjaKdYa1Y" // The Token can be found in the Credentials section
private let callId: String = "hAkz8sO5XBsW" // The CallId can be found in the Credentials section
init() {
// Simple theming: Change the local user avatar
let user = User(
id: userId,
name: "Martin", // name and imageURL are used in the UI
imageURL: .init(string: "https://picsum.photos/id/64/200/200")
)
/*
// MARK: Create an instance of the Colors struct
var customColor = Colors()
// Define the custom color you want to use
let pineGreen = Color(red: 0.0, green: 0.408, blue: 0.28)
// Swap the standard built-in color with the custom color
// Color for xmark (close icon), invite button, cancel search, and remote participant's avatar
customColor.tintColor = pineGreen
// Slashed icons: Microphone and video
customColor.accentRed = .orange
// Mute/unmute me button
customColor.secondaryButton = pineGreen
// Call controls background
customColor.callControlsBackground = pineGreen
// Online indicator icon
customColor.onlineIndicatorColor = pineGreen
// Background of an active call
customColor.callBackground = UIColor(pineGreen.opacity(0.5))
// Background of form and search field
customColor.background1 = UIColor(pineGreen.opacity(0.25))
// Color for the reject call icon
customColor.hangUpIconColor = .orange
// MARK: Create an instance of the Images class
let customImage = Images()
customImage.acceptCall = Image(systemName: "teletype.answer.circle.fill")
// Reject call icon
customImage.hangup = Image(systemName: "teletype.circle.fill")
customImage.micTurnOn = Image(systemName: "music.mic.circle.fill")
customImage.micTurnOff = Image(systemName: "mic.fill.badge.xmark")
// An icon for viewing the call participants
customImage.participants = Image(systemName: "person.2.crop.square.stack.fill")
customImage.searchIcon = Image(systemName: "sparkle.magnifyingglass")
// Clear search icon
customImage.searchCloseIcon = Image(systemName: "person.fill.xmark")
customImage.speakerOn = Image(systemName: "speaker.wave.2.circle")
customImage.speakerOff = Image(systemName: "speaker.slash.circle")
customImage.videoTurnOn = Image(systemName: "video.fill.badge.checkmark")
customImage.videoTurnOff = Image(systemName: "video.slash.circle.fill")
// Cancel icon
customImage.xmark = Image(systemName: "xmark.app.fill")
customImage.toggleCamera = Image(systemName: "camera.on.rectangle.fill")
// MARK: Create an instance of the Fonts struct
var customFont = Fonts()
// Remote participant's label
customFont.caption1 = .custom("SmoochSans-Bold", size: 24)
// Participants' names
customFont.bodyBold = .custom("SmoochSans-Bold", size: 24)
// Invite and mute button labels
customFont.headline = .custom("SmoochSans-Bold", size: 24)
// MARK: Create an instance of the Sounds class
let customSound = Sounds()
// Tell the SDK to pick the custom ring tone
//customSound.bundle = Bundle.main
// Swap the outgoing call sound with the custom one
//customSound.outgoingCallSound = "ringing.mp3"
// Create an instance of the appearance class
let customAppearance = Appearance(colors: customColor, images: customImage, fonts: customFont, sounds: customSound)
*/
// Initialize Stream Video client
self.client = StreamVideo(
apiKey: apiKey,
user: user,
token: .init(stringLiteral: token)
)
// MARK: Added by Amos for customization
_ = StreamVideoUI(
streamVideo: client
//appearance: customAppearance
)
self.viewModel = .init()
}
var body: some Scene {
WindowGroup {
VStack {
if viewModel.call != nil {
//CallContainer(viewFactory: DefaultViewFactory.shared, viewModel: viewModel)
CallContainer(viewFactory: CustomViewFactory(), viewModel: viewModel)
} else {
Text("loading...")
}
}.onAppear {
Task {
guard viewModel.call == nil else { return }
// You can join the call since it is already created
viewModel.joinCall(callType: .default, callId: callId)
// Notify an outgoing call with a custom ringtone
//viewModel.startCall(callType: .default, callId: callId, members: [], ring: true)
// Enter lobby
//viewModel.enterLobby(callType: .livestream, callId: callId, members: [])
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment