Skip to content

Commit

Permalink
Remove legacy getStats polyfill
Browse files Browse the repository at this point in the history
which provides a way to turn legacy stats into a maplike object.
Legacy getStats have since been removed from Chrome.

Fixes #1137
  • Loading branch information
fippo committed Mar 24, 2024
1 parent 3d2ea98 commit 1d2d87f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 69 deletions.
1 change: 0 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ declare module "webrtc-adapter" {
shimMediaStream(window: Window): void;
shimOnTrack(window: Window): void;
shimGetSendersWithDtmf(window: Window): void;
shimGetStats(window: Window): void;
shimSenderReceiverGetStats(window: Window): void;
shimAddTrackRemoveTrackWithNative(window: Window): void;
shimAddTrackRemoveTrack(window: Window): void;
Expand Down
1 change: 0 additions & 1 deletion src/js/adapter_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export function adapterFactory({window} = {}, options = {
chromeShim.shimOnTrack(window, browserDetails);
chromeShim.shimAddTrackRemoveTrack(window, browserDetails);
chromeShim.shimGetSendersWithDtmf(window, browserDetails);
chromeShim.shimGetStats(window, browserDetails);
chromeShim.shimSenderReceiverGetStats(window, browserDetails);
chromeShim.fixNegotiationNeeded(window, browserDetails);

Expand Down
67 changes: 0 additions & 67 deletions src/js/chrome/chrome_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,73 +188,6 @@ export function shimGetSendersWithDtmf(window) {
}
}

export function shimGetStats(window) {
if (!window.RTCPeerConnection) {
return;
}

const origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function getStats() {
const [selector, onSucc, onErr] = arguments;

// If selector is a function then we are in the old style stats so just
// pass back the original getStats format to avoid breaking old users.
if (arguments.length > 0 && typeof selector === 'function') {
return origGetStats.apply(this, arguments);
}

// When spec-style getStats is supported, return those when called with
// either no arguments or the selector argument is null.
if (origGetStats.length === 0 && (arguments.length === 0 ||
typeof selector !== 'function')) {
return origGetStats.apply(this, []);
}

const fixChromeStats_ = function(response) {
const standardReport = {};
const reports = response.result();
reports.forEach(report => {
const standardStats = {
id: report.id,
timestamp: report.timestamp,
type: {
localcandidate: 'local-candidate',
remotecandidate: 'remote-candidate'
}[report.type] || report.type
};
report.names().forEach(name => {
standardStats[name] = report.stat(name);
});
standardReport[standardStats.id] = standardStats;
});

return standardReport;
};

// shim getStats with maplike support
const makeMapStats = function(stats) {
return new Map(Object.keys(stats).map(key => [key, stats[key]]));
};

if (arguments.length >= 2) {
const successCallbackWrapper_ = function(response) {
onSucc(makeMapStats(fixChromeStats_(response)));
};

return origGetStats.apply(this, [successCallbackWrapper_,
selector]);
}

// promise-support
return new Promise((resolve, reject) => {
origGetStats.apply(this, [
function(response) {
resolve(makeMapStats(fixChromeStats_(response)));
}, reject]);
}).then(onSucc, onErr);
};
}

export function shimSenderReceiverGetStats(window) {
if (!(typeof window === 'object' && window.RTCPeerConnection &&
window.RTCRtpSender && window.RTCRtpReceiver)) {
Expand Down

0 comments on commit 1d2d87f

Please sign in to comment.