MediaStream: addtrack event

The addtrack event is fired when a new MediaStreamTrack object has been added to a MediaStream.

Bubbles No
Cancelable No
Interface MediaStreamTrackEvent
Event handler property onaddtrack

Examples

Using addEventListener():

let stream = new MediaStream();

stream.addEventListener('addtrack', (event) => {
  console.log(`New ${event.track.kind} track added`);
});

Using the onaddtrack event handler property:

let stream = new MediaStream();

stream.onaddtrack = (event) => {
  console.log(`New ${event.track.kind} track added`);
};

Specifications

Specification
Media Capture and Streams
# event-mediastream-addtrack

Browser compatibility

BCD tables only load in the browser

See also