Skip to content

Commit 5c1b2d3

Browse files
committed
add analytics report logging
1 parent 9d1d514 commit 5c1b2d3

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

peer/generate.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
protoc --ts_out=src --experimental_allow_proto3_optional --ts_opt=client_generic --proto_path proto/v1 ./proto/v1/signaling.proto
5+
node ./scripts/patch.cjs
6+
sed -i '1s;^;// @ts-nocheck\n;' ./src/google/protobuf/timestamp.ts

peer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"scripts": {
22-
"gen": "protoc --ts_out=src --experimental_allow_proto3_optional --ts_opt=client_generic --proto_path proto/v1 ./proto/v1/signaling.proto && node ./scripts/patch.cjs",
22+
"gen": "bash ./generate.bash",
2323
"dev": "vite",
2424
"build": "tsup src/index.ts --format esm,cjs --dts --minify",
2525
"clean": "rm -rf dist",

peer/proto

peer/src/google/protobuf/timestamp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
// @generated by protobuf-ts 2.9.4 with parameter client_generic
23
// @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3)
34
// tslint:disable

peer/src/peer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Timestamp } from "./google/protobuf/timestamp.ts";
1919

2020
export type { PeerInfo } from "./signaling.ts";
2121

22-
const ANALYTICS_POLL_INTERVAL_MS = 60_000;
22+
const ANALYTICS_POLL_INTERVAL_MS = 5_000;
2323

2424
/**
2525
* Streamline real-time application development.`@pulsebeam/peer` abstracts
@@ -313,10 +313,11 @@ export class Peer {
313313
start() {
314314
if (this._state === "closed") throw new Error("peer is already closed");
315315
this.transport.listen();
316-
if (
317-
this.opts.disableAnalytics != undefined ||
318-
this.opts.disableAnalytics === false
319-
) {
316+
const analyticsEnabled = this.opts.disableAnalytics == undefined ||
317+
this.opts.disableAnalytics === false;
318+
319+
this.logger.info(`analytics ${analyticsEnabled ? "enabled" : "disabled"}`);
320+
if (analyticsEnabled) {
320321
this.analyticsLoop();
321322
}
322323
}

peer/src/signaling.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ export interface AnalyticsEvent {
334334
*/
335335
tags?: AnalyticsTags;
336336
/**
337-
* @generated from protobuf field: pulsebeam.v1.AnalyticsMetric metrics = 3;
337+
* @generated from protobuf field: pulsebeam.v1.AnalyticsMetrics metrics = 3;
338338
*/
339-
metrics?: AnalyticsMetric;
339+
metrics?: AnalyticsMetrics;
340340
}
341341
/**
342342
* @generated from protobuf message pulsebeam.v1.AnalyticsTags
@@ -354,9 +354,9 @@ export interface AnalyticsTags {
354354
/**
355355
* "scaled" = trunc(X * 10^3)
356356
*
357-
* @generated from protobuf message pulsebeam.v1.AnalyticsMetric
357+
* @generated from protobuf message pulsebeam.v1.AnalyticsMetrics
358358
*/
359-
export interface AnalyticsMetric {
359+
export interface AnalyticsMetrics {
360360
/**
361361
* The overall derived quality score:
362362
* - 80-100: excellent
@@ -690,7 +690,7 @@ class AnalyticsEvent$Type extends MessageType<AnalyticsEvent> {
690690
super("pulsebeam.v1.AnalyticsEvent", [
691691
{ no: 1, name: "timestamp", kind: "message", T: () => Timestamp },
692692
{ no: 2, name: "tags", kind: "message", T: () => AnalyticsTags },
693-
{ no: 3, name: "metrics", kind: "message", T: () => AnalyticsMetric }
693+
{ no: 3, name: "metrics", kind: "message", T: () => AnalyticsMetrics }
694694
]);
695695
}
696696
}
@@ -712,17 +712,17 @@ class AnalyticsTags$Type extends MessageType<AnalyticsTags> {
712712
*/
713713
export const AnalyticsTags = new AnalyticsTags$Type();
714714
// @generated message type with reflection information, may provide speed optimized methods
715-
class AnalyticsMetric$Type extends MessageType<AnalyticsMetric> {
715+
class AnalyticsMetrics$Type extends MessageType<AnalyticsMetrics> {
716716
constructor() {
717-
super("pulsebeam.v1.AnalyticsMetric", [
717+
super("pulsebeam.v1.AnalyticsMetrics", [
718718
{ no: 1, name: "quality_score", kind: "scalar", T: 18 /*ScalarType.SINT64*/, L: 0 /*LongType.BIGINT*/ }
719719
]);
720720
}
721721
}
722722
/**
723-
* @generated MessageType for protobuf message pulsebeam.v1.AnalyticsMetric
723+
* @generated MessageType for protobuf message pulsebeam.v1.AnalyticsMetrics
724724
*/
725-
export const AnalyticsMetric = new AnalyticsMetric$Type();
725+
export const AnalyticsMetrics = new AnalyticsMetrics$Type();
726726
// @generated message type with reflection information, may provide speed optimized methods
727727
class AnalyticsReportResp$Type extends MessageType<AnalyticsReportResp> {
728728
constructor() {

0 commit comments

Comments
 (0)