--- 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;
function
是用户自定义的一个函数,写法上不带 ()
和任何参数,也可以是一个匿名函数,例如 function(event) {...}
。事件处理函数通常有个event做参数,类型为 {{domxref("MediaStreamEvent")}}.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.