--- title: RTCPeerConnection.onaddstream slug: Web/API/RTCPeerConnection/onaddstream translation_of: Web/API/RTCPeerConnection/onaddstream ---

{{APIRef("WebRTC")}}{{SeeCompatTable}}

当类型为{{domxref("MediaStreamEvent")}}的{{event("addstream")}} 事件发生时,通过{{domxref("RTCPeerConnection")}}触发RTCPeerConnection.onaddstream 事件处理函数。当远程媒体流{{domxref("MediaStream")}} 添加到连接后发送事件。当{{domxref("RTCPeerConnection.setRemoteDescription()")}} 后此事件立即被调用而不需要等待SDP交换完成。

语法

peerconnection.onaddstream = function;

例子

pc.onaddstream = function(ev) { alert("onaddstream event detected!"); };

规范

Specification Status Comment
{{ SpecName('WebRTC 1.0', '#widl-RTCPeerConnection-onaddstream', 'RTCPeerConnection.onaddstream') }} {{ Spec2('WebRTC 1.0') }} Initial specification.

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} [1] {{ CompatVersionUnknown }} [1] {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

[1] Though this property is not prefixed, the interface it belongs to is.

扩展阅读