Expose single trackCallReconnecting() entry point on PosthogAnalytics

This commit is contained in:
fkwp
2026-05-07 15:10:54 +02:00
parent 533c4fea09
commit 7cedc308ca
3 changed files with 17 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ import {
CallDisconnectedEventTracker,
CallConnectDurationTracker,
CallReconnectingTracker,
type CallReconnectingReason,
} from "./PosthogEvents";
import { Config } from "../config/Config";
import { getUrlParams } from "../UrlParams";
@@ -422,5 +423,13 @@ export class PosthogAnalytics {
public eventQualitySurvey = new QualitySurveyEventTracker();
public eventCallDisconnected = new CallDisconnectedEventTracker();
public eventCallConnectDuration = new CallConnectDurationTracker();
public eventCallReconnecting = new CallReconnectingTracker();
private readonly _eventCallReconnecting = new CallReconnectingTracker();
public trackCallReconnecting(
callId: string,
reason: CallReconnectingReason,
): void {
this._eventCallReconnecting.track(callId, reason);
this.eventCallEnded.cacheReconnecting(reason);
}
}

View File

@@ -696,12 +696,8 @@ describe("LocalMembership", () => {
it("fires CallReconnecting with the homeserver reason when homeserver disconnects", async () => {
const scope = new ObservableScope();
const trackSpy = vi.spyOn(
PosthogAnalytics.instance.eventCallReconnecting,
"track",
);
const cacheSpy = vi.spyOn(
PosthogAnalytics.instance.eventCallEnded,
"cacheReconnecting",
PosthogAnalytics.instance,
"trackCallReconnecting",
);
const hsConnected$ = new BehaviorSubject<boolean>(true);
@@ -738,7 +734,6 @@ describe("LocalMembership", () => {
defaultCreateLocalMemberValues.callId,
"syncing",
);
expect(cacheSpy).toHaveBeenCalledWith("syncing");
scope.end();
});
@@ -746,8 +741,8 @@ describe("LocalMembership", () => {
it("reports livekit reason when livekit disconnects but homeserver is fine", async () => {
const scope = new ObservableScope();
const trackSpy = vi.spyOn(
PosthogAnalytics.instance.eventCallReconnecting,
"track",
PosthogAnalytics.instance,
"trackCallReconnecting",
);
const connectionState$ = new BehaviorSubject<ConnectionState>(
@@ -795,8 +790,8 @@ describe("LocalMembership", () => {
it("fires one event per reconnection, not once per condition change", async () => {
const scope = new ObservableScope();
const trackSpy = vi.spyOn(
PosthogAnalytics.instance.eventCallReconnecting,
"track",
PosthogAnalytics.instance,
"trackCallReconnecting",
);
const hsConnected$ = new BehaviorSubject<boolean>(true);

View File

@@ -536,8 +536,7 @@ export const createLocalMembership$ = ({
)
.subscribe(([_, homeserverReason]) => {
const reason = homeserverReason !== null ? homeserverReason : "livekit";
PosthogAnalytics.instance.eventCallReconnecting.track(callId, reason);
PosthogAnalytics.instance.eventCallEnded.cacheReconnecting(reason);
PosthogAnalytics.instance.trackCallReconnecting(callId, reason);
});
// inform the widget about the connect and disconnect intent from the user.