RTCRtpSender.setStreams()
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
-
mediaStreamor[mediaStream...]Optional -
An
MediaStreamobject—or an array of multipleMediaStreamobjects—identifying the streams to which theRTCRtpSender'strackbelongs. 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
| Specification |
|---|
| WebRTC 1.0: Real-Time Communication Between Browsers (WebRTC 1.0) # dom-rtcrtpsender-setstreams |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
setStreams |
76 |
79 |
No |
No |
63 |
14.1 |
79 |
76 |
No |
54 |
14.5 |
12.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/setStreams