Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTCStatsReport should inherit or extend from Map #58995

Open
ibc opened this issue Jun 24, 2024 · 2 comments
Open

RTCStatsReport should inherit or extend from Map #58995

ibc opened this issue Jun 24, 2024 · 2 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@ibc
Copy link

ibc commented Jun 24, 2024

⚙ Compilation target

ESNEXT

⚙ Library

No idea why this item is mandatory

Missing / Incorrect Definition

RTCStatsReport is defined as follows:

/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCStatsReport) */
interface RTCStatsReport {
    forEach(callbackfn: (value: any, key: string, parent: RTCStatsReport) => void, thisArg?: any): void;
}

As per documentation, RTCStatsReport is a Map-like object so it should include methods such as values(), entries() and members such as size. Note that it must NOT include delete(), clear() or set() since it's read-only (see doc links at the bottom).

However RTCStatsReport TypeScript definition only exposes forEach().

Sample Code

const pc = new RTCPeerConnection();

pc.createDataChannel('foo', { negotiated: true, id: 123, ordered: true });

const stats = await pc.getStats();

console.log('--- num stats:', stats.size);

for (const [id, stat] of stats) {
	console.log('--- stat:', stat);
	console.log('--- stats.get(id):', stats.get(id));
}

Produces:

--- num stats: 2
--- stat: {id: 'D37', timestamp: 1719306842612.802, type: 'data-channel', bytesReceived: 0, bytesSent: 0, …}
--- stats.get(id): {id: 'D37', timestamp: 1719306842612.802, type: 'data-channel', bytesReceived: 0, bytesSent: 0, …}
--- stat: {id: 'P', timestamp: 1719306842612.802, type: 'peer-connection', dataChannelsClosed: 0, dataChannelsOpened: 0}
--- stats.get(id): {id: 'P', timestamp: 1719306842612.802, type: 'peer-connection', dataChannelsClosed: 0, dataChannelsOpened: 0}

Documentation Link

@RyanCavanaugh
Copy link
Member

Sample Code: N/A

The reason we ask for sample code is so that we can inspect a value of this type at runtime and verify the things you're saying about it.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jun 24, 2024
@ibc
Copy link
Author

ibc commented Jun 25, 2024

The reason we ask for sample code is so that we can inspect a value of this type at runtime and verify the things you're saying about it.

Thanks. I've added sample code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants