OTPublisherKit

A publisher captures an audio-video stream from the sources you specify. You can then publish the audio-video stream to an OpenTok session by sending the [OTSession publish:error:] message.

The OpenTok iOS SDK supports publishing on all multi-core iOS devices. See "Developer and client requirements" in the README file for the OpenTok iOS SDK.

Properties

delegate

Type: id<OTPublisherKitDelegate>

The OTPublisherDelegate object, which is the delegate for the OTPublisher object.

See also [OTPublisherKit audioLevelDelegate], [OTPublisherKit networkStatsDelegate], and [OTPublisherKit rtcStatsReportDelegate].

audioLevelDelegate

Type: id<OTPublisherKitAudioLevelDelegate>

Periodically receives reports of audio levels for this publisher.

This is a separate delegate object from that set as the delegate property (the OTPublisherKitDelegate object).

If you do not set this property, the audio sampling subsystem is disabled.

networkStatsDelegate

Type: id<OTPublisherKitNetworkStatsDelegate>

The OTPublisherKitNetworkStatsDelegate object that periodically receives publisher quality statistics.

This delegate object is sent messages reporting the following:

  • Total audio and video packets lost
  • Total audio and video packets received
  • Total audio and video bytes received

This is a separate delegate object from that set as the [OTPublisherKit delegate] property (the OTPublisherKitDelegate object).

Also see [OTPublisherKit rtcStatsReportDelegate].

rtcStatsReportDelegate

Type: id<OTPublisherKitRtcStatsReportDelegate>

The OTPublisherKitRtcStatsReportDelegate that reports RTC stats for the publisher. The [OTPublisherKitRtcStatsReportDelegate publisher:rtcStatsReport:] message is sent in reponse to calling the [OTPublisherKit getRtcStatsReport] method.

session

Type: OTSession *

The session that owns this publisher.

stream

Type: OTStream *

The OTStream object associated with the publisher.

name

Type: NSString *

A string that will be associated with this publisher's stream. This string is displayed at the bottom of subscriber videos associated with the published stream, if an overlay to display the name exists.

The name must be set at initialization, when you when you send the [OTPublisherKit initWithDelegate:settings:] message.

This value defaults to an empty string.

publishAudio

Type: BOOL

Whether to publish audio.

The default value is TRUE.

publishVideo

Type: BOOL

Whether to publish video.

The default value is TRUE.

publishCaptions

Type: BOOL

Whether to make captions active.

The default value is FALSE.

captionsInputLanguage

Type: NSString *

The preferred captions input language for this publisher. Use one of the supported BCP-47 language codes or nil to reset to default.

If the language code is not supported, the value will not be applied. Read this property back after setting it to verify the language was correctly accepted.

videoCapture

Type: id<OTVideoCapture>

The OTVideoCapture instance used to capture video to stream to the OpenTok session.

videoType

Type: OTPublisherKitVideoType

Specifies the type of video for the published stream.

Set this to one of the following values:

  • OTPublisherKitVideoTypeScreen — Optimizes the video encoding for screen sharing. To publish a screen-sharing stream, you need to implement a custom video capturer for the OTPublisherKit object. See [OTPublisherKit videoCapture]. It is recommended to use a low frame rate (5 frames per second or lower) with this video type. When using the screen video type in a session that uses the OpenTok Media Server, the OTPublisherKitSettings audio fallback properties are set to NO by default; this disables the audio-only fallback feature, so that the video does not drop out in subscribers. See the OpenTok Media Router.
  • OTPublisherKitVideoTypeCamera — This is the default setting, which you should use when using a camera as the video source.

videoRender

Type: id<OTVideoRender>

The OTVideoRender instance used to render video to stream to the OpenTok session.

maxVideoBitrate

Type: int

The maximum video bitrate for the publisher's video stream, in bits per second (bps).

This property sets an explicit upper limit on the publisher’s video bitrate, between 5,000 and 10,000,000. Setting this property to 0 clears any manual cap and reverts to the default preset-based adaptive bitrate behavior with no explicit limit.

When reading this property, it returns the currently configured maximum bitrate in bps. If no manual bitrate has been set, or if a bitrate preset is active, the value is 0.

A value of 0 indicates that no explicit bitrate limit is applied and the stream operates under adaptive preset rules to optimize quality.

Also see [OTPublisherKit videoBitratePreset] and Publisher Max Bitrate.

videoBitratePreset

Type: OTVideoBitratePreset

The video bitrate preset strategy applied to the publisher's video stream.

This property configures a predefined bitrate strategy to balance video quality and bandwidth usage. Available presets include default behavior, moderate bandwidth saving, and aggressive bandwidth saving modes. Preset strategies allow control over encoder behavior without specifying explicit bitrate values.

Preset configurations and manual bitrate settings are mutually exclusive. Setting maxVideoBitrate will override any preset and automatically change this property’s value to OTVideoBitratePresetCustom.

Reading this property returns the currently active preset. If a custom bitrate has been manually set, the value will be OTVideoBitratePresetCustom.

The default value is OTVideoBitratePresetDefault.

Also see [OTPublisherKit maxVideoBitrate] and Publisher Max Bitrate.

degradationPreference

Type: OTDegradationPreference

The preferred policy that the video engine will follow when adjusting frame rate and resolution to limited bandwidth and CPU conditions. See OTDegradationPreference for a description of the possible values.

targetScalabilityMode

Type: NSString *

The target scalability mode that was explicitly set via setTargetScalabilityMode:error:. Returns the last value passed to the setter, or null if the setter has never been called. This reflects the user's intent, not the mode actually applied (which may differ due to codec-dependent fallback).

This is a beta feature.

videoTransformers

Type: NSArray *

Array of OTVideoTransformer in the order to be applied to the stream.

audioTransformers

Type: NSArray *

Array of OTAudioTransformer in the order to be applied to the stream.

Methods

Name Description
getRtcStatsReport() Gets the RTC stats report for the publisher.
setTargetScalabilityMode:error:(mode, error) The target scalability mode (SVC - Scalable Video Coding) for this publisher.
initWithDelegate:(delegate) → {instancetype} Initialize a publisher object and specify the delegate object.
initWithDelegate:settings:(delegate, settings) → {instancetype} Initialize the publisher with settings defined by an OTPublisherKitSettings object.
initWithDelegate:name:(delegate, __attribute) → {instancetype} Initialize a publisher object, and specify the delegate object and the stream's name.
initWithDelegate:name:audioTrack:videoTrack:(delegate, name, audioTrack, __attribute) → {instancetype} Initialize the publisher, and specify whether audio and video will be enabled for this instance.
init() → {instancetype}

getRtcStatsReport()

Gets the RTC stats report for the publisher. This is an asynchronous operation. Set the [OTPublisherKit rtcStatsReportDelegate] property and implement the [OTPublisherKitRtcStatsReportDelegate publisher:rtcStatsReport:] method prior to calling this method. When the stats are available, the implementation of the [OTPublisherKitRtcStatsReportDelegate publisher:rtcStatsReport:] message is sent.

Also see [OTPublisherKit networkStatsDelegate] and [OTSubscriberKit getRtcStatsReport].

setTargetScalabilityMode:error:(mode, error)

The target scalability mode (SVC - Scalable Video Coding) for this publisher. The scalability mode controls the number of spatial (resolution) and temporal (frame rate) layers that WebRTC encodes. The mode is applied to the Media Router media path.

The setter may be called at any time — it does not require the media path negotiation to have completed. The mode will be applied once the Media Router media path is established.

If a non-SVC codec (VP8, H.264) is negotiated on the Media Router media path, the closest applicable mode is used: spatial layers are forced to 1, preserving the temporal dimension (e.g. L2T2 → L1T2 when VP8 is negotiated).

Parameters:
Name Type Description
mode NSString * The desired scalability mode string (e.g. "L1T3"). Must be one of: L1T1, L1T2, L1T3, L2T1, L2T2, L2T3, L3T1, L3T2, L3T3.
error NSError * * On failure, set to an OTError with domain OT_PUBLISHER_ERROR_DOMAIN and code OTPublisherInvalidScalabilityMode.

initWithDelegate:(delegate) → {instancetype}

Initialize a publisher object and specify the delegate object.

When running in the XCode iOS Simulator, this method returns nil.

Parameters:
Name Type Description
delegate id<OTPublisherKitDelegate> The delegate (OTPublisherKitDelegate) object for the publisher.
Returns:

The pointer to the instance, or nil if initialization failed.

initWithDelegate:settings:(delegate, settings) → {instancetype}

Initialize the publisher with settings defined by an OTPublisherKitSettings object.

Parameters:
Name Type Description
delegate id<OTPublisherKitDelegate> The delegate (OTPublisherKitDelegate) object for the publisher.
settings OTPublisherKitSettings * The (OTPublisherKitSettings) object that defines settings for the publisher.
Returns:

initWithDelegate:name:(delegate, __attribute) → {instancetype}

Initialize a publisher object, and specify the delegate object and the stream's name.

This method is deprecated. Use [OTPublisherKit initWithDelegate:settings:] instead.

When running in the XCode iOS Simulator, this method returns nil.

Parameters:
Name Type Description
delegate id<OTPublisherKitDelegate> The delegate (OTPublisherKitDelegate) object for the publisher.
__attribute (deprecated(("Use initWithDelegate: settings: instead")))
Returns:

The pointer to the instance, or nil if initialization failed.

initWithDelegate:name:audioTrack:videoTrack:(delegate, name, audioTrack, __attribute) → {instancetype}

Initialize the publisher, and specify whether audio and video will be enabled for this instance.

This method is deprecated. Use [OTPublisherKit initWithDelegate:settings:] instead.

If either audioTrack or videoTrack are set to NO, the respective subsystem will not be initialized, and setting the corresponding [OTPublisherKit publishAudio] and [OTPublisherKit publishVideo] properties will have no effect.

If your application does not require the use of audio or video, it is recommended to set these values rather than use the [OTPublisherKit publishAudio] and [OTPublisherKit publishVideo] properties, which only temporarily disable the tracks.

Parameters:
Name Type Description
delegate id<OTPublisherKitDelegate> The delegate (OTPublisherKitDelegate) object for the publisher.
name NSString * The name of the publisher video. The [OTStream name] property for a stream published by this publisher will be set to this value (on all clients).
audioTrack BOOL Whether to publish audio (YES) or not (NO).
__attribute (deprecated(("Use initWithDelegate: settings: instead")))
Returns:

init() → {instancetype}

Returns: