Properties | properties object | Methods | Events
The OTPublisher
component will initialize a publisher and publish to the specified session upon mounting. To destroy the publisher, unmount the OTPublisher
component. Please keep in mind that the publisher view is not removed unless you specifically unmount the OTPublisher
component.
Add the OTPublisher component as a child of the OTSession component:
class App extends Component {
constructor(props) {
super(props);
this.publisherProperties = {
publishAudio: true,
publishVideo: false,
publishCaptions: true,
cameraPosition: 'front'
};
this.publisherEventHandlers = {
streamCreated: event => {
console.log('Publisher stream created!', event);
},
streamDestroyed: event => {
console.log('Publisher stream destroyed!', event);
}
};
}
render() {
return (
<OTSession apiKey="your-api-key" sessionId="your-session-id" token="your-session-token">
<OTPublisher
properties={this.publisherProperties}
eventHandlers={this.publisherEventHandlers}
style={{ height: 100, width: 100 }}
/>
</OTSession>
);
}
}
The OTPublisher component has the following props, each of which is optional:
sessionId
(String) -- The OpenTok session ID. This is auto-populated by wrapping
OTPublisher
with OTSession
, so you generally do not need to set this property for the OTPublisher.
properties
(Object) -- Options for the publisher instance. See the following section,
properties object. The properties
object is used for initial set up
of the Publisher. The OTPublisher
object watches for changes on a few keys of the properties
object,
and makes the necessary changes. Currently these are:
cameraPosition -- Sets the camera to 'front' or 'back'.
publishAudio -- Toggles audio on (true
) or off false
.
publishVideo -- Toggles video on (true
) or off false
.
publishCaptions -- Toggles captions on (true
) or off false
for the published stream.
eventHandlers
(Object) -- An object containing key-value pairs of event names and
callback functions for event handlers. See Events.
The properties
object passed into the OTPublisher object has the following properties:
audioBitrate (Number) -- The desired bitrate for the published audio, in bits per second. The supported range of values is 6,000 - 510,000. (Invalid values are ignored.) Set this value to enable high-quality audio (or to reduce bandwidth usage with lower-quality audio).
The following are recommended settings:
The default value is 40,000.
audioFallbackEnabled (Object) —- Setting for the audio-fallback feature.
The audioFallback
object includes two Boolean properties:
publisher
— Whether to enable (true
) or disable (false
)
publisher audio fallback. With publisher audio fallback enabled, when the stream's quality has degraded significantly (for example, because of network conditions), the publisher disables video in order to preserve audio quality. The default is false
(publisher audio fallback is disabled).
subscriber
— Whether to enable (true
) or disable (false
) subscriber audio fallback. This setting only applies in routed sessions (sessions that use the OpenTok Media Router. Subscriber audio fallback is not supported in relayed session. With subscriber audio fallback enabled, when the OpenTok Media Router determines that a stream's quality has degraded significantly for a specific subscriber, it disables the video in that subscriber in order to preserve audio quality. For streams that use
a camera as a video source, the default setting is true
(the audio-fallback feature is enabled). The default setting is false
(the audio-fallback feature is disabled) for screen-sharing streams (
which have the videoSource
property set to "screen" in OTPublisher component). This setting replaces the audioFallbackEnabled
property, which will be deprecated.
audioFallbackEnabled (Boolean) —- Deprecated. This is replaced by the subscriber
property of the audioFallback
property (see above).
audioTrack (Boolean) -- If this property is set to false, the audio subsystem will not be initialized for the publisher, and setting the publishAudio
property will have no effect. If your application does not require the use of audio, it is recommended to set this property rather than use the publishAudio property, which only temporarily disables the audio track.
cameraPosition (String) -- The preferred camera position. When setting this property, if the change is possible, the publisher will use the camera with the specified position. Valid inputs are 'front' (the default) and 'back'.
enableDtx (Boolean) - Whether to enable Opus DTX. The default value is false
. Setting this to true can reduce bandwidth usage in streams that have long periods of silence.
frameRate (Number) - The desired frame rate, in frames per second, of the video. Valid values are 30, 15, 7, and 1. The published stream will use the closest value supported on the publishing client. The frame rate can differ slightly from the value you set, depending on the device of the client. And the video will only use the desired frame rate if the client configuration supports it.
name (String) -- A string that will be associated with this publisher’s stream. This string is displayed at the bottom of publisher videos and at the bottom of subscriber videos associated with the published stream. If you do not specify a value, the name is set to the device name.
publishAudio (Boolean) -- Whether to publish audio. The default is true
.
publishVideo (Boolean) -- Whether to publish video. The default is true
.
publishCaptions (Boolean) — Whether to publish captions. Note that the session must have captions enabled (using the Video API REST method or server SDK) and the publisher must be publishing audio. For more information, see the Live Captions developer guide.
scalableScreenshare (Boolean) -- Whether to allow use of scalable video for a screen-sharing publisher (true) or not (false, the default). This only applies to a publisher that has the videoSource
set to "screen".
resolution (String) - The desired resolution of the video. The format of the string is "widthxheight", where the width and height are represented in pixels. Valid values are "1920x1080", "1280x720", "640x480", and "352x288". The published video will only use the desired resolution if the client configuration supports it. Some devices and clients do not support each of these resolution settings.
videoContentHint (String) -- Sets the content hint of the video track of the publisher's stream. You can set this to one of the following values: "", "motion", "details" or "text". For additional information, see the documentation for the videoContentHint
option of the
OT.initPublisher()
method of the OpenTok.js SDK.
videoTrack (Boolean) -- If this property is set to false, the video subsystem will not be initialized for the publisher, and setting the publishVideo property will have no effect. If your application does not require the use of video, it is recommended to set this property rather than use the publishVideo property, which only temporarily disables the video track.
videoSource (String) -- To publish a screen-sharing stream, set this property to "screen". If you do not specify a value, this will default to "camera".
getRtcStatsReport() Gets the RTC stats report for the publisher. This is an asynchronous operation.
The OTPublisher object dispatches an rtcStatsReport
event when RTC statistics for the publisher are available.
setAudioTransformers() -- Sets audio transformers for the publisher.
Important: To use this method, you need to add the Vonage Media Transformer library to your project, separately from the OpenTok React Native SDK. For details, see Vonage Media Library integration.
One audio transformer is supported -- the noise suppression filter.
This method has one parameter -- and array of objects defining each transformer to apply to the publisher's stream. A transformer object has two properties:
name
(String) -- Set this to 'NoiseSuppression'
.
properties
(String) -- Set this to an empty string.
To remove audio transformers from the published stream, call the OTPublisher.setAudioTransformers()
method and pass in an empty array.
Important: Media transformations, such as the noise suppression filter, are resource-intensive and require devices with high processing power. It is recommended to only use these transformations on supported devices. See the following documentation:
For more information on transformers, see Using the Vonage Media Processor library
setVideoTransformers() -- Sets video transformers for the publisher.
Important: In version 2.28.0+ of the Vonage Video React Native SDK, to use this method you need to add the Vonage Media Library separately from the Vonage Video React Native SDK. For details, see Vonage Media Library integration.
This method has one parameter -- and array of objects defining each transformer to apply to the publisher's stream. A transformer object has two properties:
name
(String) -- Either 'BackgroundBlur' (for a background blur filter) or 'BackgroundReplacement' (for a background image replacement filter).
properties
(String) -- A JSON string with the properties of the Vonage video transformer.
For a background blur transformer, the format of the JSON is:
`{
"radius" :"None"
}`
Valid values for the radius property are "None", "High", and "Low".
For a custom background blur transformer, the format of the JSON is:
`{
"radius": "Custom",
"custom_radius": "value"
}`
custom_radius
can be any positive integer.
For a background replacement transformer, the format of the JSON is:
`{
"image_file_path": "path/to/image"
}`
Where image_file_path
is the absolute file path of a local image to use as virtual background. Supported image formats are PNG and JPEG.
To remove video transformers from the published stream, call the OTPublisher.setVideoTransformers() method and pass in an empty array.
Important: Media transformations, such as background blur and background replacement, are resource-intensive and require devices with high processing power. It is recommended to only use these transformations on supported devices. See the following documentation:
For more information on transformers, see Using the Vonage Media Processor library
audioLevel (Number) -- The audio level, from 0 to 1.0. Adjust this value logarithmically for use in adjusting a user interface element, such as a volume meter. Use a moving average to smooth the data.
audioNetworkStats (Object) — Sent periodically to report audio statistics for the publisher. A PublisherAudioNetworkStatsEvent object is passed into the event handler.
error (Object) -- Sent if the publisher encounters an error. After this message is sent, the publisher can be considered fully detached from a session and may be released.
muteForced -- Sent when a moderator has forced this client to mute audio.
otrnError (Object) -- Sent if there is an error with the communication between the native publisher instance and the JS component.
rtcStatsReport (Object) -- Sent when RTC stats reports are available for the publisher,
in response to calling the OTPublisher.getRtcStatsReport()
method. A
PublisherRtcStatsReportEvent object is passed into
the event handler. This event has an array of
objects. For a routed session (a seesion that uses the
OpenTok Media Router),
this array includes one object, defining the statistics for the single video media stream that is sent
to the OpenTok Media Router. In a relayed session, the array includes an object for each subscriber
to the published stream. Each object includes two properties:
connectionId
-- For a relayed session (in which a publisher sends individual media streams
to each subscriber), this is the unique ID of the client’s connection.
jsonArrayOfReports
-- A JSON array of RTC stats reports for the media stream. The structure
of the JSON array is similar to the format of the RtcStatsReport object implemented in web browsers
(see the Mozilla docs).
Also see this W3C documentation.
streamCreated (Object) -- Sent when the publisher starts streaming. A streamingEvent object is passed into the event handler.
streamDestroyed (Object) -- Sent when the publisher stops streaming. A streamingEvent object is passed into the event handler.
videoDisabled -- Sent when the publisher stops sending video because of publisher audio fallback.
videoDisableWarning -- Sent when the publisher is close to going to audio-only fallback becuase of declining network conditions. See publisher audio fallback.
videoDisableWarningLifted -- Sent after a videoDisableWarning event when network conditions improve. See publisher audio fallback.
videoEnabled -- Sent when the publisher resumes sending video after it was disabled because of publisher audio fallback.
videoNetworkStats (Object) -- Sent periodically to report audio statistics for the publisher. A PublisherVideoNetworkStatsEvent object is passed into the event handler.