이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.

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 web site or application, so you will not typically need to instantiate an RTCTrackEvent yourself.

Constructor

RTCTrackEvent()
Creates and returns a new 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.

Properties

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 which comprise the track that was added to the connection. By default, the array is empty.
track Read only
The MediaStreamTrack which has been added to the connection.
transceiver Read only
The RTCRtpTransceiver being used by the new track.

Track event types

There is only one type of track event.

track

The 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 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.

Example

This simple example creates an event listener for the track event which sets the srcObject of the <video> element with the ID "videobox" to the first stream in the list passed in the event's streams array.

peerConnection.addEventListener("track", e => {
  let videoElement = document.getElementById("videobox");
  videoElement.srcObject = e.streams[0];
}, false);

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCTrackEvent' in that specification.
Candidate Recommendation Initial specification.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 56Edge Full support YesFirefox Full support 22IE No support NoOpera Full support 43Safari ? WebView Android Full support 56Chrome Android Full support 56Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0
receiverChrome Full support 56Edge Full support YesFirefox Full support 22IE No support NoOpera Full support 43Safari ? WebView Android Full support 56Chrome Android Full support 56Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0
streamsChrome Full support 56Edge Full support YesFirefox Full support 22IE No support NoOpera Full support 43Safari ? WebView Android Full support 56Chrome Android Full support 56Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0
trackChrome Full support 56Edge Full support YesFirefox Full support 22IE No support NoOpera Full support 43Safari ? WebView Android Full support 56Chrome Android Full support 56Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0
transceiverChrome Full support 56Edge Full support YesFirefox Full support 59IE No support NoOpera Full support 43Safari ? WebView Android Full support 56Chrome Android Full support 56Edge Mobile Full support YesFirefox Android Full support 59Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

문서 태그 및 공헌자

이 페이지의 공헌자: Sheppy
최종 변경자: Sheppy,