过时
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);
					

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

元数据

  • 最后修改: