WebRTC API
interface
RTCTrackEvent
表示
track
event, which is sent when a new
MediaStreamTrack
is added to an
RTCRtpReceiver
which is part of the
RTCPeerConnection
.
The target is the
RTCPeerConnection
object to which the track is being added.
This event is sent by the WebRTC layer to the web site or application, so you will not typically need to instantiate an
RTCTrackEvent
yourself.
RTCTrackEvent()
RTCTrackEvent
object, initialized with properties taken from the specified
RTCTrackEventInit
dictionary. You will probably not need to create new track events yourself, since they're typically created by the WebRTC infrastructure and sent to the connection's
ontrack
event handler.
由于
RTCTrackEvent
基于
事件
, its properties are also available.
receiver
只读
RTCRtpReceiver
used by the track that's been added to the
RTCPeerConnection
.
流
只读
可选
MediaStream
objects, each representing one of the media streams to which the added
track
belongs. By default, the array is empty, indicating a streamless track.
track
只读
MediaStreamTrack
which has been added to the connection.
transceiver
只读
RTCRtpTransceiver
being used by the new track.
There is only one type of track event.
track
track
event is sent to the
RTCPeerConnection
when a new track has been added to the connection. By the time the
track
event is delivered to the
RTCPeerConnection
's
ontrack
handler, the new media has completed its negotiation for a specific
RTCRtpReceiver
(which is specified by the event's
receiver
特性)。
此外,
MediaStreamTrack
specified by the receiver's
track
is the same one specified by the event's
track
, and the track has been added to any associated remote
MediaStream
对象。
You can add a
track
event listener to be notified when the new track is available so that you can, for example, attach its media to a
<video>
element, using either
RTCPeerConnection.addEventListener()
或
ontrack
event handler property.
注意:
It may be helpful to keep in mind that you receive the
track
event when a new inbound track has been added to your connection, and you call
addTrack()
to add a track to the far end of the connection, thereby triggering a
track
event on the remote peer.
This simple example creates an event listener for the
track
event which sets the
srcObject
的
<video>
element with the ID
videobox
to the first stream in the list passed in the event's
流
数组。
peerConnection.addEventListener("track", e => {
let videoElement = document.getElementById("videobox");
videoElement.srcObject = e.streams[0];
}, false);
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCTrackEvent' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
RTCTrackEvent
|
Chrome 56 | Edge ≤18 | Firefox 22 | IE No | Opera 43 | Safari Yes | WebView Android 56 | Chrome Android 56 | Firefox Android 44 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 6.0 |
receiver
|
Chrome 56 | Edge ≤18 | Firefox 22 | IE No | Opera 43 | Safari Yes | WebView Android 56 | Chrome Android 56 | Firefox Android 44 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 6.0 |
流
|
Chrome 56 | Edge ≤18 | Firefox 22 | IE No | Opera 43 | Safari Yes | WebView Android 56 | Chrome Android 56 | Firefox Android 44 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 6.0 |
track
|
Chrome 56 | Edge ≤18 | Firefox 22 | IE No | Opera 43 | Safari Yes | WebView Android 56 | Chrome Android 56 | Firefox Android 44 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 6.0 |
transceiver
|
Chrome 69 | Edge ≤18 | Firefox 59 | IE No | Opera 43 | Safari Yes | WebView Android 69 | Chrome Android 69 | Firefox Android 59 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
RTCTrackEvent
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnection
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport