removeTrack

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The RTCPeerConnection.removeTrack() method tells the local end of the connection to stop sending media from the specified track, without actually removing the corresponding RTCRtpSender from the list of senders as reported by RTCPeerConnection.getSenders(). If the track is already stopped, or is not in the connection's senders list, this method has no effect.

If the connection has already been negotiated (signalingState is set to "stable"), it is marked as needing to be negotiated again; the remote peer won't experience the change until this negotiation occurs. A notificationneeded event is sent to the RTCPeerConnection to let the local end know this negotiation must occur.

Syntax

JavaScript
pc.removeTrack(sender);

Parameters

mediaTrack
A RTCRtpSender specifying the sender to remove from the connection.

Exceptions

InvalidStateError
The connection is not open.

Example

This example adds a video track to a connection and sets up a listener on a close button which removes the track when the user clicks the button.

JavaScript
var pc, sender;
navigator.getUserMedia({video: true}, function(stream) {
  pc = new RTCPeerConnection();
  var track = stream.getVideoTracks()[0];
  sender = pc.addTrack(track, stream);
}

document.getElementById("closeButton").addEventListener("click", function(event) {
  pc.removeTrack(sender);
  pc.close();
}, false);

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browser
The definition of 'RTCPeerConnection.removeTrack()' in that specification.
Working Draft Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support No support (Yes)[1] No support (Yes) ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? No support ? ?

[1] Firefox currently removes the RTCRtpSender from the list of senders as reported by RTCPeerConnection.getSenders(). This was correct in earlier versions of the specification, but no longer is. See bug 1290949.

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/rtcpeerconnection/removetrack

Experimental Method Reference removeTrack RTCPeerConnection WebRTC