Skip to content

Commit

Permalink
Send a dummy insightsStats event to rtc stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thyal committed Jan 18, 2024
1 parent 168bd78 commit 75508c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/lib/core/redux/slices/rtcAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export const doRtcAnalyticsCustomEventsInitialize = createAppThunk(() => (dispat

if (!rtcManager) return;

// RTC stats require a `insightsStats` event to be sent to set the timestamp.
// This is a temporary workaround, we just send one dummy event on initialization.
rtcManager.sendStatsCustomEvent("insightsStats", {
_time: Date.now(),
ls: 0,
lr: 0,
bs: 0,
br: 0,
cpu: 0,
});

Object.values(rtcAnalyticsCustomEvents).forEach(({ rtcEventName, getValue, getOutput }) => {
const value = getValue(state);
const output = { ...(getOutput(value) as Record<string, unknown>), _time: Date.now() };
Expand Down
3 changes: 2 additions & 1 deletion src/lib/core/redux/tests/store/rtcAnalytics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStore } from "../store.setup";
import { createStore, mockRtcManager } from "../store.setup";
import { doRtcAnalyticsCustomEventsInitialize, rtcAnalyticsState } from "../../slices/rtcAnalytics";
import { diff } from "deep-object-diff";

Expand Down Expand Up @@ -27,5 +27,6 @@ describe("actions", () => {
"userRole",
])
);
expect(mockRtcManager.sendStatsCustomEvent).toHaveBeenCalledWith("insightsStats", expect.any(Object));
});
});

0 comments on commit 75508c9

Please sign in to comment.