Skip to main content

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

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)
}
}

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

Channel is live

Example channel is offline

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.")
}
}