RTCRtpSender.setStreams() - Web APIs 编辑

The RTCRtpSender method setStreams() associates the sender's track with the specified MediaStream or array of MediaStream objects.

Syntax

rtcRtpSender.setStreams(mediaStream);
rtcRtpSender.setStreams([mediaStream...]);

Parameters

mediaStream or [mediaStream...] Optional
An MediaStream object—or an array of multiple MediaStream objects—identifying the streams to which the RTCRtpSender's track belongs. If this parameter isn't specified, no new streams will be associated with the track.

Return value

None.

Exceptions

InvalidStateError
The sender's connection is closed.

Description

setStreams() is purely additive. It doesn't remove the track from any streams; it adds it to new ones. If you specify streams to which the track already belongs, that stream is unaffected.

Once the track has been added to all of the streams, renegotiation of the connection will be triggered by the negotiationneeded event being dispatched to the RTCPeerConnection to which the sender belongs.

Example

This example adds all of an RTCPeerConnection's tracks to the specified stream.

function addTracksToStream(stream) {
  let senders = pc.getSenders();

  senders.forEach((sender) => {
    if (sender.track && (sender.transport.state === connected)) {
      sender.setStreams(stream);
    }
  });
}

After calling the RTCPeerConnection method getSenders() to get the list of the connection's senders, the addTracksToStream() function iterates over the list. For each sender, if the sender's track is non-null and its transport's state is connected, we call setStreams() to add the track to the stream specified.

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCRtpSender.setStreams()' in that specification.
Candidate Recommendation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:132 次

字数:3853

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文