How do I use RTC SDK for web to ingest streams when no microphones are available?

更新时间:
复制 MD 格式

This topic describes how to use Real-Time Communication (RTC) SDK for web to ingest streams when no microphones are available.

  1. Enable the subscription-only mode for your browser. This way, you can skip the browser check.
    aliWebrtc.isSupport({isReceiveOnly: true}).then((re)=>{
        // The subscription-only mode is supported.
    }).catch(err => {
        // The subscription-only mode is not supported.
    })
  2. Query the audio track that you want to replace and call the setExternalMediaTrack method to replace the audio track with an external audio source.
    // Query the media track.
    let mediaStream = video.captureStream(); // video indicates the type of the media track that you want to query.
    // Query audio tracks.
    let audiotracks = mediaStream && mediaStream.getAudioTracks()
    // Select the audio track that you want to replace.
    let audiotrack = (audiotracks && audiotracks.length) ? audiotracks[0]
    // Replace the audio track with an external audio source.
    aliWebrtc.setExternalMediaTrack(audiotrack, 0);
    Note
    • Before the replacement, make sure that you stop ingesting streams.
    • Every time you stop ingesting streams, you must configure an external audio source again.
  3. Ingest streams. You do not need to ingest a stream for the audio track. RTC SDK for web identifies that a stream is ingested for the external audio source, so the browser check is skipped.