Skip to content

Commit 9135ce1

Browse files
Merge pull request #33 from Eyevinn/frontend/non-blocking-init-with-queuing
feat: non-blocking init with event queuing
2 parents abe2b34 + a148ad0 commit 9135ce1

7 files changed

Lines changed: 925 additions & 96 deletions

File tree

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ export {
77
PlayerAnalyticsConnector,
88
IPlayerAnalyticsConnectorInitOptions,
99
} from "./src/PlayerAnalyticsConnector";
10+
11+
export type {
12+
TAnalyticsSendError,
13+
TOnSendError,
14+
} from "./src/utils/Reporter";

spec/PlayerAnalytics.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { PlayerAnalytics, IPlayerAnalyticsInitOptions } from "../src/PlayerAnalytics";
2-
import { Reporter } from "../src/utils/Reporter";
1+
import {
2+
PlayerAnalytics,
3+
IPlayerAnalyticsInitOptions,
4+
} from "../src/PlayerAnalytics";
35
import {
46
TPlayingEvent,
57
TPausedEvent,
@@ -157,7 +159,8 @@ describe("PlayerAnalytics", () => {
157159
expect(mockFetch).toHaveBeenCalled();
158160
const body = JSON.parse(mockFetch.calls.argsFor(0)[1].body);
159161
expect(body.event).toBe("playing");
160-
expect(body.sessionId).toBe("test-session");
162+
// Reporter uses its authoritative sessionId (from server init response)
163+
expect(body.sessionId).toBe("test-session-id");
161164
});
162165

163166
it("should call reporter.send with correct data for pause()", () => {
@@ -295,7 +298,10 @@ describe("PlayerAnalytics", () => {
295298

296299
describe("debug mode", () => {
297300
it("should not call fetch when debug mode is enabled", async () => {
298-
const analytics = new PlayerAnalytics("https://example.com/analytics", true);
301+
const analytics = new PlayerAnalytics(
302+
"https://example.com/analytics",
303+
true
304+
);
299305

300306
spyOn(console, "log");
301307

@@ -306,7 +312,10 @@ describe("PlayerAnalytics", () => {
306312
});
307313

308314
it("should log events to console in debug mode", async () => {
309-
const analytics = new PlayerAnalytics("https://example.com/analytics", true);
315+
const analytics = new PlayerAnalytics(
316+
"https://example.com/analytics",
317+
true
318+
);
310319

311320
spyOn(console, "log");
312321

0 commit comments

Comments
 (0)