MaestroKit: LiveBadge Component Documentation
The liveBadge
component is a custom view that displays the status of a Maestro channel. It can show the channel's status as either "live" with the number of concurrent viewers or "offline".
Usage
- SwiftUI
- UIKit
import SwiftUI
import MaestroKit
struct ContentView: View {
@EnvironmentObject var maestroSDK: Maestro
let channelId: String
var body: some View {
maestroSDK.liveBadge(channelId: channelId)
}
}
struct ContentView_Previews: PreviewProvider {
@EnvironmentObject static var maestroSDK: Maestro
static var previews: some View {
ContentView(channelId: "YOUR_CHANNEL_ID")
.environmentObject(maestroSDK)
}
}
import UIKit
import SwiftUI
import MaestroKit
class ViewController: UIViewController {
var maestroSDK = Maestro()
override func viewDidLoad() {
super.viewDidLoad()
let swiftUIView = maestroSDK.liveBadge(channelId: "YOUR_CHANNEL_ID").environmentObject(maestroSDK)
let hostingController = UIHostingController(rootView: swiftUIView)
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hostingController.view.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
hostingController.didMove(toParent: self)
}
}
Replace "YOUR_CHANNEL_ID" with the actual channel ID you want to display the status for.
Parameters
The liveBadge component accepts the following parameters:
- channelId (required): The unique ID of the Maestro channel for which you want to display the status. Make sure to provide a valid channel ID.
Behavior
The liveBadge component will automatically update its display based on the channel's status. If the channel is live, it will show the number of concurrent viewers. If the channel is offline, it will display the word "OFFLINE".
Example channel is live
Example channel is offline
Use the isChannelLive method to decide if you should render the component or not
isChannelLive(channelId: String, completion: @escaping (Bool) -> Void): This method checks if the specified channel is live. The result is provided through the completion closure, which receives a Bool parameter indicating true if the channel is live and false otherwise.example:
Maestro.isChannelLive(channelId: "YOUR_CHANNEL_ID") { isLive in
if isLive {
print("The channel is live!")
} else {
print("The channel is offline.")
}
}