Skip to content

Errors

Methods that publish tracks or change a published track throw RoomError. These are the cases they throw:

Case Thrown by What to do
videoPublicationAlreadyExists LocalParticipant.publish(videoTrack:to:options:) Each friend gets one video publication. Unpublish the current one, then publish again.
audioPublicationAlreadyExists LocalParticipant.publish(audioTrack:to:options:) Each friend gets one audio publication. Unpublish the current one, then publish again.
trackNotPublished LocalTrackPublication.setCodec(_:), LocalTrackPublication.setMaxFps(_:), LocalTrackPublication.setVp8Encoding(_:), LocalTrackPublication.setH264Encoding(_:), LocalTrackPublication.requestKeyframe() The publication was unpublished. Publish the track again to get a new one.
codecNotSupported LocalTrackPublication.setVp8Encoding(_:), LocalTrackPublication.setH264Encoding(_:) The publication uses the other codec. Call LocalTrackPublication.setCodec(_:) to change codec and settings together.
invalidParameter LocalTrackPublication.setCodec(_:), LocalTrackPublication.setVp8Encoding(_:), LocalTrackPublication.setH264Encoding(_:), LocalTrackPublication.setMaxFps(_:) A value is out of range: maxBitrate must be positive, the frame rate must be 1 to 60. The name and reason say which.

videoPublicationAlreadyExists and audioPublicationAlreadyExists carry the friend ID, codecNotSupported carries the codec the call needs, and invalidParameter carries the parameter name and the reason.

initialize(_:) throws its own error type, RevueInitError; see Initialization and configuration.

Publishing

import RevueSDK

/// Send the camera to a friend. Each friend gets one video publication, so when the
/// screen share already goes to that friend, unpublish it and publish the camera instead.
@MainActor
func publishCamera(to participant: RemoteParticipant) async throws -> LocalTrackPublication {
    let local = Room.shared.localParticipant!
    do {
        return try await local.publish(videoTrack: local.cameraTrack, to: participant)
    } catch RoomError.videoPublicationAlreadyExists {
        if let screen = local.videoPublication(source: .screenShareVideo, to: participant.identity) {
            local.unpublish(publication: screen)
        } else if let camera = local.videoPublication(source: .camera, to: participant.identity) {
            return camera
        }
        return try await local.publish(videoTrack: local.cameraTrack, to: participant)
    }
}

Changing a publication

import RevueSDK

/// Switch a video publication to the low-latency VP8 preset.
/// Returns false when the publication was unpublished in the meantime.
@MainActor
func useLowLatencyVideo(_ publication: LocalTrackPublication) throws -> Bool {
    do {
        try publication.setVp8Encoding(.lowLatency)
    } catch RoomError.codecNotSupported {
        // The publication sends H.264: change the codec instead of the VP8 settings.
        try publication.setCodec(.vp8LowLatency)
    } catch RoomError.trackNotPublished {
        return false
    }
    return true
}

/// Apply a frame rate the user typed in. Returns why it was rejected, or nil when it was applied.
@MainActor
func applyFrameRate(_ publication: LocalTrackPublication, fps: Int) throws -> String? {
    do {
        try publication.setMaxFps(fps)
        return nil
    } catch RoomError.invalidParameter(let name, let reason) {
        return "\(name) \(reason)"
    }
}