Publishing tracks¶
Publishing sends one of your tracks to one connected participant. There is no server in between, so every
publish names its recipient with to:, and only that participant receives the track. To send your camera to
three people, publish it three times.
Publish to a participant¶
LocalParticipant.publishCamera(to:options:) and LocalParticipant.publishMicrophone(to:options:) publish
your camera and microphone. For any other track, such as a buffer track, use
LocalParticipant.publish(videoTrack:to:options:) or LocalParticipant.publish(audioTrack:to:options:).
Each publish returns a LocalTrackPublication, the copy of the track that goes to that participant.
import RevueSDK
/// Send your camera and microphone to one participant. Each publish goes to that participant only:
/// to send to three people, publish three times.
@MainActor
func publishCameraAndMicrophone(to participant: RemoteParticipant) async throws {
guard let local = Room.shared.localParticipant else { return }
try await local.publishCamera(to: participant)
try await local.publishMicrophone(to: participant)
}
Each friend gets at most one video publication and one audio publication. Publishing a second video track to
the same friend throws RoomError.videoPublicationAlreadyExists(friendId:), and a second audio track
throws RoomError.audioPublicationAlreadyExists(friendId:). To switch from your camera to a screen share,
unpublish the camera first; see Errors.
Publish to participants who connect later¶
The SDK does not publish anything on its own. A participant who connects after you have published to the
others receives none of your tracks until you publish to them too. Publishing to each new participant is a
required step: do it when your RoomDelegate receives participantDidConnect.
import RevueSDK
/// The SDK does not publish to a participant who connects later. Publish to each one yourself
/// in participantDidConnect, or they will not see or hear you.
final class PublishToNewParticipants: RoomDelegate {
var onPublishFailed: ((RemoteParticipant, Error) -> Void)?
func room(_ room: Room, participantDidConnect participant: RemoteParticipant) {
Task { @MainActor in
guard let local = Room.shared.localParticipant else { return }
do {
try await local.publishCamera(to: participant)
try await local.publishMicrophone(to: participant)
} catch {
onPublishFailed?(participant, error)
}
}
}
}
Publishing and turning on the camera¶
Publishing does not turn on the camera, and turning on the camera does not publish. Do them in whichever order suits your app:
- If you publish before the camera is on, the publication waits: nothing is sent until the first frame arrives, and the participant sees you from that frame on.
- If the track is muted when you publish, the participant sees that your camera is off from the start, and sees you as soon as you unmute.