Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. RTCPeerConnection
  4. removeTrack()

RTCPeerConnection: removeTrack() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨January 2020⁩.

TheremoveTrack() method of theRTCPeerConnection interface tells the local end of the connection to stop sending media from the specified track, without actually removing the correspondingRTCRtpSender from the list of senders as reported byRTCPeerConnection.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.Anegotiationneeded event is sent to theRTCPeerConnection to let the local end know this negotiation must occur.

Syntax

js
removeTrack(sender)

Parameters

sender

ARTCRtpSender specifying the sender to remove from the connection.

Return value

undefined.

Exceptions

InvalidStateErrorDOMException

Thrown if 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.

js
let pc;let sender;navigator.getUserMedia({ video: true }, (stream) => {  pc = new RTCPeerConnection();  const [track] = stream.getVideoTracks();  sender = pc.addTrack(track, stream);});document.getElementById("closeButton").addEventListener("click", (event) => {  pc.removeTrack(sender);  pc.close();});

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# dom-rtcpeerconnection-removetrack

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp