过时
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.
过时
addstream
event is sent to an
RTCPeerConnection
when new media, in the form of a
MediaStream
object, has been added to it.
重要:
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
.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
MediaStreamEvent
|
| 事件处理程序特性 |
RTCPeerconnection.onaddstream
|
You can, similarly, watch for streams to be removed from the connection by monitoring the
removestream
事件。
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
是
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
.
还可以使用
addEventListener()
method to set an event listener:
pc.addEventListener("addstream", ev => doAddStream(ev.stream), false);
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
addstream
event
弃用
非标
|
Chrome 24 | Edge 15 | Firefox 22 | IE No | Opera 43 | Safari No | WebView Android Yes | Chrome Android 25 | Firefox Android 44 | Opera Android 43 | Safari iOS ? | Samsung Internet Android 6.0 |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。