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
被设为
"stable"
), it is marked as needing to be negotiated again; the remote peer won't experience the change until this negotiation occurs. A
negotiationneeded
event is sent to the
RTCPeerConnection
to let the local end know this negotiation must occur.
pc.removeTrack(sender);
mediaTrack
RTCRtpSender
specifying the sender to remove from the connection.
undefined
.
InvalidStateError
The connection is not open.
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.
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.removeTrack()' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
removeTrack
|
Chrome 64 | Edge ≤18 | Firefox 22 | IE No | Opera 51 | Safari 11 | WebView Android 64 | Chrome Android 64 | Firefox Android 44 | Opera Android 47 | Safari iOS Yes | Samsung Internet Android 6.0 |
完整支持
不支持
RTCPeerConnection
canTrickleIceCandidates
connectionState
currentLocalDescription
currentRemoteDescription
getDefaultIceServers()
iceConnectionState
iceGatheringState
localDescription
onaddstream
onconnectionstatechange
ondatachannel
onicecandidate
oniceconnectionstatechange
onicegatheringstatechange
onidentityresult
onidpassertionerror
onidpvalidationerror
onnegotiationneeded
onpeeridentity
onremovestream
onsignalingstatechange
ontrack
peerIdentity
pendingLocalDescription
pendingRemoteDescription
remoteDescription
sctp
signalingState
addIceCandidate()
addStream()
addTrack()
close()
createAnswer()
createDataChannel()
createOffer()
generateCertificate()
getConfiguration()
getIdentityAssertion()
getReceivers()
getSenders()
getStats()
getStreamById()
getTransceivers()
removeStream()
removeTrack()
restartIce()
setConfiguration()
setIdentityProvider()
setLocalDescription()
setRemoteDescription()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent