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

feat: collect more granular RTC stats #1735

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

feat: collect more granular RTC stats #1735

wants to merge 9 commits into from

Conversation

oliverlaz
Copy link
Member

Overview

Implements the new RTC stats collection flow. Switches to max-bundle RTCPeerConnection bundle policy

Implementation notes

Comment on lines +5 to +8
string, // method name
string | null, // id
RTCStatsDataType, // payload
number, // timestamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use TypeScript's labeled tuple elements.

private buffer: [
  methodName: string,
  id: string | null,
  payload: RTCStatsDataType,
  timestamp: number,
];

* transforms a maplike to an object. Mostly for getStats + JSON.parse(JSON.stringify())
* @param {*} m
*/
export const map2obj = (m: Map<string, any>): Record<string, any> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be replaced with Object.fromEntries, which is widely available.

const getStats = () => {
pc.getStats(null).then((stats) => {
const now = map2obj(stats as Map<string, any>);
const base = JSON.parse(JSON.stringify(now)); // our new prev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to clone here? It will be cloned in deltaCompression anyway.

trace('ontrack', id, `${e.track.kind}:${e.track.id} ${streams}`);
});
pc.addEventListener('signalingstatechange', () => {
trace('onsignalingstatechange', id, pc.signalingState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but I think this is a better place to dispose interval (if (pc. signalingState === 'closed')). Then pc instance can be cleaned up as soon as the connection is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants