Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Audio Fallback — React Native

Use the OpenTok audio fallback API to dynamically prioritize audio in response to network quality.

For conceptual information, see the audio fallback overview.

Note: The audioFallbackEnabled prop of the OTPublisher component will be deprecated. Please use the audioFallback.subscriber setting instead.

This topic includes the following sections:

Enabling and disabling audio-only fallback

Set the audioFallback property of the properties prop you pass into the OTPublisher component:

// Enable subscriber audio fallback (the default)
// and publisher audio fallback:
<OTPublisher
  properties={{
    audioFallback={
      publisher: true,
    },
  }}
/>
});

// Enable publisher audio fallback and disable subscriber audio fallback:
<OTPublisher
  properties={{
    audioFallback: {
      publisher: true,
      subscriber: false,
    },
  }}
/>

// Enable subscriber audio fallback and disable publisher audio fallback:
<OTPublisher
  properties={{
    audioFallback: {
      publisher: false,
      subscriber: true,
    },
  }}
/>

// Disable both publisher audio fallback (the default)
// and subscriber audio fallback:
<OTPublisher
  properties={{
    audioFallback: {
      subscriber: false,
    },
  }}
/>

The audioFallback object includes two Boolean properties:

Publisher audio fallback events

When publisher audio fallback is enabled, callback methods of the OTPublisher component are invoked in response to changing quality conditions:

For example the following code adds event listeners for audio fallback-related events (so that you can provide user interface notifications):

<OTPublisher
  properties={{
    audioFallback: {
      publisher: true,
    }
  }}

  eventHandlers={{
    videoDisableWarning: () => {
      // Add UI notification
    },
    videoDisableWarningLifted: () => {
      // Adjust UI notification
    },
    videoDisabled: () => {
      // Add UI notification
    },
    videoEnabled: () => {
      // Remove UI notification
    },
  }}
/>

Subscriber audio fallback events

The OTSubscriber component includes callback methods that are invoked based on events related to the video being enabled or disabled for the subscriber's stream:

The OTSubscriber videoDisableWarning() and videoDisableWarningLifted() callback methods are only invoked in sessions that use the OpenTok Media Router (sessions with the media mode set to routed).

For example the following code adds event listeners for audio fallback-related events (so that you can provide user interface notifications):

<OTSubscriber
  eventHandlers={{
    videoDisableWarning: () => {
      // Add UI notification
    },
    videoDisableWarningLifted: () => {
      // Adjust UI notification
    },
    videoDisabled: () => {
      // Add UI notification
    },
    videoEnabled: () => {
      // Remove UI notification
    },
  }}
/>