Streams
Managing live streams happens through the stream store component that you can retrieve with
VideoKit.streams()
. Just like other network APIs, you will need a valid session
to perform these operation successfully. All functions of this component are asynchronous
and will return the usual Call
object, described here.
Creating streams
We recommend to let the stream host component create streams for you, but should you need to do it, you can do so as follows:
val streams: StreamStore = VideoKit.streams()
streams.create("low-latency").onSuccess {
// Got stream!
}.onError {
// Something went wrong
}
Fetching a stream
To retrieve a stream by its id, simply use get
:
val streams: StreamStore = VideoKit.streams()
streams.get("stream_id").onSuccess {
// Got stream!
}.onError {
// Something went wrong
}
You can also subscribe to stream changes using observe
. It returns an ObjectRegistration
that you can listen to and be notified whenever the stream changes. This is especially
useful for monitoring the stream state property.
val streams: StreamStore = VideoKit.streams()
val registration: ObjectRegistration<Stream> = streams.observe("stream_id")
registration.addListener(object : ObjectListener<Stream> {
override fun onObjectChanged(old: Stream?, new: Stream?) {
// Stream changed from old to new!
}
})
Deleting streams
To delete a stream, all you need is its id:
val streams: StreamStore = VideoKit.streams()
streams.delete(stream.id).onSuccess {
// Deleted!
}.onError {
// Something went wrong
}
Querying streams
To query for available streams, you can use the query
API. The function accepts a
request object which can be configured to filter streams by state. For example, to retrieve
all streams that are in the live state:
val streams: StreamStore = VideoKit.streams()
streams.query(StreamRequest(state = "live")).onSuccess {
// Got streams!
}.onError {
// Something went wrong
}