Skip to main content
Version: 4.x.x

Go Live On Social Media - iOS

This feature lets a participant broadcast the room on social media platforms such as Facebook or YouTube. This guide shows how a participant can start and stop broadcasting the room.

  1. Start LiveStream - By using startLivestream() function, a participant can start broadcasting the room on various platforms by providing the URL and stream key of each platform.
  2. Stop LiveStream - By using stopLivestream() function, a participant can stop broadcasting on all platforms.

Both methods are async throws. Call them with try await inside a Task, after you join the room. When a call fails, it throws a VideoSDKError.

Start And Stop Live Stream​

/// keep track of livestream
private var livestreamStarted = false

@IBAction func livestreamButtonTapped(_ sender: Any) {
Task {
do {
if !livestreamStarted {
// prepare output
// specify social-media-url and stream-key
let output = LivestreamOutput(url: "<rtmp://a.rtmp.youtube.com/live2>", streamKey: "<stream-key>")

// start livestream
try await self.room?.startLivestream(outputs: [output])
}
else {
// stop livestream
try await self.room?.stopLivestream()
}
} catch {
print("Livestream request failed: \(error)")
}
}
}

Events​

  1. onLivestreamStarted - Whenever broadcasting of the room started, onLivestreamStarted event will trigger.

  2. onLivestreamStopped - Whenever broadcasting of the room stopped, onLivestreamStopped event will trigger.

/// Called after livestream starts
func onLivestreamStarted() {
livestreamStarted = true

// show indication that livestream is started
}

/// Called after livestream stops
func onLivestreamStopped() {
livestreamStarted = false

// hide livestream indication
}

Got a Question? Ask us on discord