This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The WebRTC API interface RTCTrackEvent represents the 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 website or application, so you will not typically need to instantiate an RTCTrackEvent yourself.
RTCTrackEvent()Creates and returns a new RTCTrackEvent object. 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.
Since RTCTrackEvent is based on Event, its properties are also available.
receiver Read only
The RTCRtpReceiver used by the track that's been added to the RTCPeerConnection.
streams Read only Optional
An array of 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 Read only
The MediaStreamTrack which has been added to the connection.
transceiver Read only
The RTCRtpTransceiver being used by the new track.
There is only one type of track event.
trackThe 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 property).
In addition, the 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 objects.
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() or the ontrack event handler property.
Note: 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 of the <video> element with the ID video-box to the first stream in the list passed in the event's streams array.
peerConnection.addEventListener(
"track",
(e) => {
let videoElement = document.getElementById("video-box");
videoElement.srcObject = e.streams[0];
},
false,
);
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
RTCTrackEvent |
64 | 79 | 46 | 51 | 11 | 64 | 46 | 47 | 11 | 9.0 | 64 | 11 |
RTCTrackEvent |
56 | 79 | 22 | 43 | 11 | 56 | 24 | 43 | 11 | 6.0 | 56 | 11 |
receiver |
56 | 79 | 34 | 43 | 11 | 56 | 34 | 43 | 11 | 6.0 | 56 | 11 |
streams |
56 | 79 | 22 | 43 | 11 | 56 | 24 | 43 | 11 | 6.0 | 56 | 11 |
track |
56 | 79 | 22 | 43 | 11 | 56 | 24 | 43 | 11 | 6.0 | 56 | 11 |
transceiver |
69 | 79 | 59 | 43 | 11 | 69 | 59 | 43 | 11 | 6.0 | 69 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCTrackEvent