let call = streamVideo.call(callType: .default, callId: callId)
Task {
try await call.join()
}
Broadcasting
The StreamVideo SDK has support for broadcasting calls. You can find a tutorial on how to implement broadcasting calls in our livestreaming tutorial.
Creating a call
First, you need to create a call with a user that has the capability to start broadcasting calls (start-broadcast-call
).
The code above will create and join the call. If you just want to create it (and not join it), you can use the method create
:
let call = try await call.create(members: members, custom: [:], startsAt: Date(), ring: false)
Start HLS
You can start HLS broadcasting a call, by calling the method startHLS
:
try await call.startHLS()
After few seconds of setup, the call would be broadcasted, and you will receive an event called BroadcastingStartedEvent
. Also, the state
of the call would be updated - the broadcasting
value would become true.
You can listen to the broadcasting events on the call by subscribing to its AsyncStream
:
for await event in call.subscribe() {
switch event {
case .typeCallHLSBroadcastingStartedEvent(let broadcastingStartedEvent):
log.debug("received an event \(broadcastingStartedEvent)")
/* handle recording event */
case .typeCallHLSBroadcastingStoppedEvent(let broadcastingStoppedEvent):
log.debug("received an event \(broadcastingStoppedEvent)")
/* handle recording event */
default:
break
}
}
In the BroadcastingStartedEvent
, you will receive the hlsPlaylistUrl
, a URL that can be used by other participants to watch the broadcasting.
Stop HLS
When you are done with broadcasting, you should call the method stopHLS
.
try await call.stopHLS()
This action will also send BroadcastingStoppedEvent
to all participants who are watching the call.