Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
The obsolete addstream
event is sent to an RTCPeerConnection
when new media, in the form of a MediaStream
object, has been added to it.
Important: This event has been removed from the WebRTC specification. You should instead watch for the track
event, which is sent for each media track added to the RTCPeerConnection
.
Bubbles | No |
---|---|
Cancelable | No |
Interface | MediaStreamEvent |
Event handler property | RTCPeerConnection.onaddstream |
You can, similarly, watch for streams to be removed from the connection by monitoring the removestream
event.
Examples
This example looks to determine if the user's browser supports the track
event. If it does, a track
event listener is set up; otherwise, an addstream
event listener is set up. pc
is an RTCPeerConnection
.
if (pc.addTrack !== undefined) { pc.ontrack = ev => { ev.streams.forEach(stream => doAddStream(stream)); } } else { pc.onaddstream = ev => { doAddStream(ev.stream); } }
This calls a function doAddStream()
once for each stream being added to the RTCPeerConnection
, regardless of whether the browser sends addstream
or track
.
You can also use the addEventListener()
method to set an event listener:
pc.addEventListener("addstream", ev => doAddStream(ev.stream), false);
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
addstream event | Chrome Full support 24 | Edge Full support 15 | Firefox Full support 22 | IE No support No | Opera Full support 43 | Safari No support No | WebView Android Full support Yes | Chrome Android Full support 25 | Firefox Android Full support 44 | Opera Android Full support 43 | Safari iOS ? | Samsung Internet Android Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.