v160 · webrtc · migration

Migration shim

Got an old softphone or call-centre bundle that still calls pc.createDTMFSender(track)? On the intent thread, the Chrome WebRTC team posted a shim that rebuilds the method on top of the standard RTCRtpSender.dtmf and reproduces Chromium’s own exceptions. This page runs real legacy code against a simulated Chrome 160, installs that shim, and checks its error behaviour against the native method case by case.

Simulation, clearly labelled: there is no flag that removes createDTMFSender early, so “Simulate Chrome 160” deletes the method from RTCPeerConnection.prototype in this tab only (and puts it back when unticked). On a browser where the method is already gone, the toggle is unavailable and the page runs against the real removal.

1 · Set up this tab

Checking for the native method…

—

2 · Run the legacy dialler

Unmodified legacy code on a real loopback call: pc.createDTMFSender(track).insertDTMF("123#").

Not run yet.

3 · Error parity: native vs shim

Each case calls the native method (when this browser still has it) and the shim’s logic directly, and compares the result. Apps that catch specific exception names need these to match.

createDTMFSender(…) outcome: native vs shim
casenativeshimmatch
Press “Compare all cases”.

—

the shim (from the intent thread)

if (window.RTCPeerConnection && !RTCPeerConnection.prototype.createDTMFSender &&
    window.RTCRtpSender && "dtmf" in RTCRtpSender.prototype) {
  RTCPeerConnection.prototype.createDTMFSender = function (track) {
    if (!(track instanceof MediaStreamTrack)) throw new TypeError("…");
    if (this.signalingState === "closed")
      throw new DOMException("…", "InvalidStateError");
    if (track.kind !== "audio") throw new DOMException("…", "SyntaxError");
    const sender = this.getSenders().find((s) => s.track === track);
    if (!sender) throw new DOMException("…", "SyntaxError");
    if (!sender.dtmf) throw new DOMException("…", "SyntaxError");
    return sender.dtmf;
  };
}

better: the two-line rewrite

// const dtmf = pc.createDTMFSender(track);                 // before
const dtmf = pc.getSenders().find((s) => s.track === track)?.dtmf;  // after
if (dtmf?.canInsertDTMF) dtmf.insertDTMF("123#");

see also