Skip to content

Commit d88b3e9

Browse files
committed
shallow object
1 parent f1d0993 commit d88b3e9

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/room/Room.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export enum ConnectionState {
144144
}
145145

146146
const CONNECTION_RECONCILE_FREQUENCY_MS = 4 * 1000;
147-
const STATS_LOG_FREQUENCY_MS = 30 * 1000;
147+
const STATS_LOG_FREQUENCY_MS = 5 * 1000;
148148

149149
/**
150150
* In LiveKit, a room is the logical grouping for a list of participants.
@@ -2616,8 +2616,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
26162616
}
26172617

26182618
/**
2619-
* Dumps the raw stats of both peer connections. They cover every track of the
2620-
* room as well as the transports, so nothing is collected per track.
2619+
* Dumps stats of both peer connections.
26212620
*/
26222621
private logWebRTCStats = async () => {
26232622
const pcManager = this.engine?.pcManager;
@@ -2629,9 +2628,13 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
26292628
pcManager.publisher.getStats(),
26302629
pcManager.subscriber?.getStats(),
26312630
]);
2632-
this.statsLog.info('webrtc stats', {
2633-
publisher: publisher && summarizeStatsReport(publisher),
2634-
subscriber: subscriber && summarizeStatsReport(subscriber),
2631+
const publisherStats = publisher && summarizeStatsReport(publisher);
2632+
const subscriberStats = subscriber && summarizeStatsReport(subscriber);
2633+
this.statsLog.info(`webrtc stats`, {
2634+
publisher: publisherStats?.connection,
2635+
subscriber: subscriberStats?.connection,
2636+
inbound: [...(publisherStats?.inbound ?? []), ...(subscriberStats?.inbound ?? [])],
2637+
outbound: publisherStats?.outbound,
26352638
});
26362639
} catch (error) {
26372640
this.statsLog.debug('could not collect webrtc stats', { error });

src/room/statsSummary.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** one summarised stats entry; keys without a value are dropped */
22
type Summary = Record<string, unknown>;
33

4-
function compact(summary: Summary): Summary {
4+
function compact<T extends Summary>(summary: T): Summary {
55
const compacted: Summary = {};
66
for (const [key, value] of Object.entries(summary)) {
77
if (value !== undefined) {
@@ -48,7 +48,7 @@ function playoutDelay(stat: Summary, playout?: Summary): number | undefined {
4848
* Picks the interesting fields out of a `getStats()` report and groups them by
4949
* RTP stream, so a stats dump can be read without unfolding the raw report.
5050
*/
51-
export function summarizeStatsReport(report: RTCStatsReport): Summary {
51+
export function summarizeStatsReport(report: RTCStatsReport) {
5252
const byId = new Map<string, Summary>();
5353
const candidatePairs: Summary[] = [];
5454
const inbound: Summary[] = [];
@@ -179,9 +179,9 @@ export function summarizeStatsReport(report: RTCStatsReport): Summary {
179179
candidatePairChanges: transport?.selectedCandidatePairChanges,
180180
});
181181

182-
return compact({
182+
return {
183183
connection: Object.keys(connection).length > 0 ? connection : undefined,
184184
outbound: outbound.length > 0 ? outbound : undefined,
185185
inbound: inbound.length > 0 ? inbound : undefined,
186-
});
186+
};
187187
}

0 commit comments

Comments
 (0)