@npaw/forge-web 9.7.0 → 9.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -111,6 +111,30 @@ interface ForgeCreateOptions extends ForgeRuntimeConfig {
111
111
  * Defaults to true.
112
112
  */
113
113
  autoDeviceIdentity?: boolean;
114
+ /**
115
+ * Disables automatic collection of the device connection type
116
+ * (`connectionType`: `wifi`, `cellular`, `ethernet`, `other` or `unknown`).
117
+ *
118
+ * Collection is on by default and reads `navigator.connection`, which only
119
+ * Chromium exposes and only over HTTPS. Elsewhere (Safari, Firefox) nothing
120
+ * is reported and the server keeps deriving the connection from GeoIP. A
121
+ * `connectionType` set through video metadata always wins.
122
+ *
123
+ * @defaultValue true
124
+ */
125
+ autoConnectionType?: boolean;
126
+ /**
127
+ * Disables location observation entirely, whatever an operator configures
128
+ * remotely.
129
+ *
130
+ * Forge never prompts for geolocation: it starts a watch only when
131
+ * `navigator.permissions` already reports `granted`, and only when an
132
+ * operator enabled one of the two motion switches. This is the local
133
+ * override for integrators who would rather Forge never touch location.
134
+ *
135
+ * @defaultValue true
136
+ */
137
+ autoLocation?: boolean;
114
138
  startSessionOnInitialize?: boolean;
115
139
  initialSessionParams?: ForgeParams;
116
140
  capture?: ForgeCaptureOptions;
@@ -454,6 +478,8 @@ declare const CAPTURE_PLAN_BITS: {
454
478
  readonly NETWORK: number;
455
479
  readonly SECTIONS: number;
456
480
  readonly ATTRIBUTION: number;
481
+ /** The operator enabled a motion switch, so location may be observed. */
482
+ readonly LOCATION: number;
457
483
  };
458
484
  declare function isCapturePlanEnabled(bits: number, bit: number): boolean;
459
485
  interface WasmTransportRequest extends ForgeTransportRequest {
@@ -705,6 +731,34 @@ interface NetworkObservation {
705
731
  timemarkMs?: number;
706
732
  }
707
733
 
734
+ /**
735
+ * Copyright (C) NPAW - All Rights Reserved
736
+ *
737
+ * This source code is protected under international copyright law. All rights
738
+ * reserved and protected by the copyright holders.
739
+ * This file is confidential and only available to authorized individuals with the
740
+ * permission of the copyright holders. If you encounter this file and do not have
741
+ * permission, please contact the copyright holders and delete this file.
742
+ *
743
+ *
744
+ * @author: Victor Soto <victor.soto@nicepeopleatwork.com>
745
+ * @description: Web location observation for viewer motion, started only when the page already holds a granted geolocation permission.
746
+ */
747
+ /**
748
+ * A location fix forwarded to the kernel.
749
+ *
750
+ * The binding forwards fixes and never verdicts: the thresholds, hysteresis
751
+ * and staleness rules live in the kernel so Web, Android and Apple cannot
752
+ * drift into three different definitions of "moving".
753
+ */
754
+ interface ForgeLocationFix {
755
+ latitude: number;
756
+ longitude: number;
757
+ /** Horizontal accuracy radius in metres. */
758
+ accuracyMetres: number;
759
+ timestampMs: number;
760
+ }
761
+
708
762
  /**
709
763
  * Copyright (C) NPAW - All Rights Reserved
710
764
  *
@@ -868,6 +922,16 @@ declare class NPAWForge {
868
922
  private defaultVideo;
869
923
  private captureHandle;
870
924
  private capturePlanUnsubscribe;
925
+ /**
926
+ * Set when automatic connection type collection is on. Held so `destroy()`
927
+ * can drop the `change` listener that belongs to this instance.
928
+ */
929
+ private connectionTypeObserver;
930
+ /**
931
+ * Created when the integrator allows it, but inert until a capture plan
932
+ * carries the location bit.
933
+ */
934
+ private locationObserver;
871
935
  private constructor();
872
936
  onEvent(listener: ForgeEventListener): () => void;
873
937
  onDiagnostic(listener: ForgeDiagnosticListener): () => void;
@@ -936,6 +1000,20 @@ declare class NPAWForge {
936
1000
  /** Reports a profile deletion: `profile_deleted {profileId}`. */
937
1001
  profileDeleted(profileId: string): Promise<ForgeResult>;
938
1002
  setLogLevel(level: string): Promise<ForgeResult>;
1003
+ /**
1004
+ * Reports the browser's current connection class to the kernel. Called by the
1005
+ * automatic observer; a `connectionType` set through video metadata keeps
1006
+ * precedence over it.
1007
+ */
1008
+ setAutoConnectionType(connectionType: string | undefined): Promise<ForgeResult>;
1009
+ /** Forwards a location fix to the kernel, which owns every threshold. */
1010
+ recordLocationFix(fix: ForgeLocationFix): Promise<ForgeResult>;
1011
+ /**
1012
+ * Starts or stops location observation to match the capture plan. Nothing is
1013
+ * observed - not even the permission state - until an operator enables one
1014
+ * of the two motion switches.
1015
+ */
1016
+ private applyLocationPlan;
939
1017
  applicationForeground(foreground: boolean): Promise<ForgeResult>;
940
1018
  trackNetworkEvent(observation: NetworkObservation): Promise<ForgeResult>;
941
1019
  videoBuilder(): VideoBuilder;
package/dist/index.d.ts CHANGED
@@ -111,6 +111,30 @@ interface ForgeCreateOptions extends ForgeRuntimeConfig {
111
111
  * Defaults to true.
112
112
  */
113
113
  autoDeviceIdentity?: boolean;
114
+ /**
115
+ * Disables automatic collection of the device connection type
116
+ * (`connectionType`: `wifi`, `cellular`, `ethernet`, `other` or `unknown`).
117
+ *
118
+ * Collection is on by default and reads `navigator.connection`, which only
119
+ * Chromium exposes and only over HTTPS. Elsewhere (Safari, Firefox) nothing
120
+ * is reported and the server keeps deriving the connection from GeoIP. A
121
+ * `connectionType` set through video metadata always wins.
122
+ *
123
+ * @defaultValue true
124
+ */
125
+ autoConnectionType?: boolean;
126
+ /**
127
+ * Disables location observation entirely, whatever an operator configures
128
+ * remotely.
129
+ *
130
+ * Forge never prompts for geolocation: it starts a watch only when
131
+ * `navigator.permissions` already reports `granted`, and only when an
132
+ * operator enabled one of the two motion switches. This is the local
133
+ * override for integrators who would rather Forge never touch location.
134
+ *
135
+ * @defaultValue true
136
+ */
137
+ autoLocation?: boolean;
114
138
  startSessionOnInitialize?: boolean;
115
139
  initialSessionParams?: ForgeParams;
116
140
  capture?: ForgeCaptureOptions;
@@ -454,6 +478,8 @@ declare const CAPTURE_PLAN_BITS: {
454
478
  readonly NETWORK: number;
455
479
  readonly SECTIONS: number;
456
480
  readonly ATTRIBUTION: number;
481
+ /** The operator enabled a motion switch, so location may be observed. */
482
+ readonly LOCATION: number;
457
483
  };
458
484
  declare function isCapturePlanEnabled(bits: number, bit: number): boolean;
459
485
  interface WasmTransportRequest extends ForgeTransportRequest {
@@ -705,6 +731,34 @@ interface NetworkObservation {
705
731
  timemarkMs?: number;
706
732
  }
707
733
 
734
+ /**
735
+ * Copyright (C) NPAW - All Rights Reserved
736
+ *
737
+ * This source code is protected under international copyright law. All rights
738
+ * reserved and protected by the copyright holders.
739
+ * This file is confidential and only available to authorized individuals with the
740
+ * permission of the copyright holders. If you encounter this file and do not have
741
+ * permission, please contact the copyright holders and delete this file.
742
+ *
743
+ *
744
+ * @author: Victor Soto <victor.soto@nicepeopleatwork.com>
745
+ * @description: Web location observation for viewer motion, started only when the page already holds a granted geolocation permission.
746
+ */
747
+ /**
748
+ * A location fix forwarded to the kernel.
749
+ *
750
+ * The binding forwards fixes and never verdicts: the thresholds, hysteresis
751
+ * and staleness rules live in the kernel so Web, Android and Apple cannot
752
+ * drift into three different definitions of "moving".
753
+ */
754
+ interface ForgeLocationFix {
755
+ latitude: number;
756
+ longitude: number;
757
+ /** Horizontal accuracy radius in metres. */
758
+ accuracyMetres: number;
759
+ timestampMs: number;
760
+ }
761
+
708
762
  /**
709
763
  * Copyright (C) NPAW - All Rights Reserved
710
764
  *
@@ -868,6 +922,16 @@ declare class NPAWForge {
868
922
  private defaultVideo;
869
923
  private captureHandle;
870
924
  private capturePlanUnsubscribe;
925
+ /**
926
+ * Set when automatic connection type collection is on. Held so `destroy()`
927
+ * can drop the `change` listener that belongs to this instance.
928
+ */
929
+ private connectionTypeObserver;
930
+ /**
931
+ * Created when the integrator allows it, but inert until a capture plan
932
+ * carries the location bit.
933
+ */
934
+ private locationObserver;
871
935
  private constructor();
872
936
  onEvent(listener: ForgeEventListener): () => void;
873
937
  onDiagnostic(listener: ForgeDiagnosticListener): () => void;
@@ -936,6 +1000,20 @@ declare class NPAWForge {
936
1000
  /** Reports a profile deletion: `profile_deleted {profileId}`. */
937
1001
  profileDeleted(profileId: string): Promise<ForgeResult>;
938
1002
  setLogLevel(level: string): Promise<ForgeResult>;
1003
+ /**
1004
+ * Reports the browser's current connection class to the kernel. Called by the
1005
+ * automatic observer; a `connectionType` set through video metadata keeps
1006
+ * precedence over it.
1007
+ */
1008
+ setAutoConnectionType(connectionType: string | undefined): Promise<ForgeResult>;
1009
+ /** Forwards a location fix to the kernel, which owns every threshold. */
1010
+ recordLocationFix(fix: ForgeLocationFix): Promise<ForgeResult>;
1011
+ /**
1012
+ * Starts or stops location observation to match the capture plan. Nothing is
1013
+ * observed - not even the permission state - until an operator enables one
1014
+ * of the two motion switches.
1015
+ */
1016
+ private applyLocationPlan;
939
1017
  applicationForeground(foreground: boolean): Promise<ForgeResult>;
940
1018
  trackNetworkEvent(observation: NetworkObservation): Promise<ForgeResult>;
941
1019
  videoBuilder(): VideoBuilder;
@@ -139,7 +139,9 @@ var NPAWForge = (() => {
139
139
  // kernel never sets them and they must never be reassigned so existing
140
140
  // bits never renumber.
141
141
  SECTIONS: 1 << 13,
142
- ATTRIBUTION: 1 << 14
142
+ ATTRIBUTION: 1 << 14,
143
+ /** The operator enabled a motion switch, so location may be observed. */
144
+ LOCATION: 1 << 15
143
145
  };
144
146
  function isCapturePlanEnabled(bits, bit) {
145
147
  return (bits & bit) !== 0;
@@ -4372,6 +4374,166 @@ var NPAWForge = (() => {
4372
4374
  };
4373
4375
  }
4374
4376
 
4377
+ // src/connection-type.ts
4378
+ function connectionTypeFromNetworkType(type) {
4379
+ switch (type) {
4380
+ case "wifi":
4381
+ return "wifi";
4382
+ case "cellular":
4383
+ return "cellular";
4384
+ case "ethernet":
4385
+ return "ethernet";
4386
+ case "bluetooth":
4387
+ case "wimax":
4388
+ case "other":
4389
+ return "other";
4390
+ case "none":
4391
+ case "unknown":
4392
+ return "unknown";
4393
+ default:
4394
+ return "unknown";
4395
+ }
4396
+ }
4397
+ var ForgeConnectionTypeObserver = class {
4398
+ constructor(publish, connection = readNavigatorConnection()) {
4399
+ this.publish = publish;
4400
+ this.connection = connection;
4401
+ }
4402
+ /**
4403
+ * Publishes the current value and starts listening. Starting twice is a
4404
+ * no-op, so a host that re-initialises does not stack listeners.
4405
+ */
4406
+ start() {
4407
+ var _a;
4408
+ const connection = this.connection;
4409
+ if (!connection || this.listener) {
4410
+ return;
4411
+ }
4412
+ this.report(connectionTypeFromNetworkType(connection.type));
4413
+ const listener = () => {
4414
+ this.report(connectionTypeFromNetworkType(connection.type));
4415
+ };
4416
+ try {
4417
+ (_a = connection.addEventListener) == null ? void 0 : _a.call(connection, "change", listener);
4418
+ this.listener = listener;
4419
+ } catch (e2) {
4420
+ }
4421
+ }
4422
+ /**
4423
+ * Stops listening and clears the published value, so a torn-down instance
4424
+ * cannot keep a stale class attached to later events.
4425
+ */
4426
+ stop() {
4427
+ var _a, _b;
4428
+ const listener = this.listener;
4429
+ this.listener = void 0;
4430
+ this.lastPublished = void 0;
4431
+ if (!listener) {
4432
+ return;
4433
+ }
4434
+ try {
4435
+ (_b = (_a = this.connection) == null ? void 0 : _a.removeEventListener) == null ? void 0 : _b.call(_a, "change", listener);
4436
+ } catch (e2) {
4437
+ }
4438
+ this.publish(void 0);
4439
+ }
4440
+ /** Publishes only genuine changes; `change` also fires on speed estimates. */
4441
+ report(observed) {
4442
+ if (this.lastPublished === observed) {
4443
+ return;
4444
+ }
4445
+ this.lastPublished = observed;
4446
+ this.publish(observed);
4447
+ }
4448
+ };
4449
+ function readNavigatorConnection() {
4450
+ const navigatorRef = globalThis.navigator;
4451
+ return navigatorRef == null ? void 0 : navigatorRef.connection;
4452
+ }
4453
+
4454
+ // src/location.ts
4455
+ var ForgeLocationObserver = class {
4456
+ constructor(publish, environment = readGeolocationEnvironment()) {
4457
+ this.starting = false;
4458
+ /** Set by stop(), so a start() awaiting its permission query gives up. */
4459
+ this.stopped = false;
4460
+ this.publish = publish;
4461
+ this.environment = environment;
4462
+ }
4463
+ /**
4464
+ * Starts observing if - and only if - the permission is already `granted`.
4465
+ * Starting twice is a no-op.
4466
+ */
4467
+ async start() {
4468
+ const environment = this.environment;
4469
+ if (!environment || this.watchId !== void 0 || this.starting) {
4470
+ return;
4471
+ }
4472
+ this.starting = true;
4473
+ this.stopped = false;
4474
+ try {
4475
+ const state = await environment.queryPermission();
4476
+ if (state !== "granted") {
4477
+ return;
4478
+ }
4479
+ if (this.watchId !== void 0 || this.stopped) {
4480
+ return;
4481
+ }
4482
+ this.watchId = environment.watchPosition(
4483
+ (position) => this.publish(fixFromPosition(position)),
4484
+ () => {
4485
+ }
4486
+ );
4487
+ } catch (e2) {
4488
+ } finally {
4489
+ this.starting = false;
4490
+ }
4491
+ }
4492
+ /** Stops observing. Safe to call when never started. */
4493
+ stop() {
4494
+ this.stopped = true;
4495
+ const watchId = this.watchId;
4496
+ this.watchId = void 0;
4497
+ if (watchId === void 0 || !this.environment) {
4498
+ return;
4499
+ }
4500
+ try {
4501
+ this.environment.clearWatch(watchId);
4502
+ } catch (e2) {
4503
+ }
4504
+ }
4505
+ };
4506
+ function fixFromPosition(position) {
4507
+ return {
4508
+ latitude: position.coords.latitude,
4509
+ longitude: position.coords.longitude,
4510
+ accuracyMetres: position.coords.accuracy,
4511
+ timestampMs: position.timestamp
4512
+ };
4513
+ }
4514
+ function readGeolocationEnvironment() {
4515
+ const navigatorRef = globalThis.navigator;
4516
+ const geolocation = navigatorRef == null ? void 0 : navigatorRef.geolocation;
4517
+ const permissions = navigatorRef == null ? void 0 : navigatorRef.permissions;
4518
+ if (!geolocation || !(permissions == null ? void 0 : permissions.query)) {
4519
+ return void 0;
4520
+ }
4521
+ return {
4522
+ queryPermission: async () => {
4523
+ const status = await permissions.query({ name: "geolocation" });
4524
+ return status == null ? void 0 : status.state;
4525
+ },
4526
+ watchPosition: (onFix, onError) => geolocation.watchPosition(onFix, onError, {
4527
+ // Coarse and cheap: this answers "moving or not", which needs neither
4528
+ // navigation-grade accuracy nor its battery cost.
4529
+ enableHighAccuracy: false,
4530
+ maximumAge: 3e4,
4531
+ timeout: 6e4
4532
+ }),
4533
+ clearWatch: (id) => geolocation.clearWatch(id)
4534
+ };
4535
+ }
4536
+
4375
4537
  // src/video.ts
4376
4538
  var PlayerAdapter = class {
4377
4539
  attach(video) {
@@ -4968,6 +5130,7 @@ var NPAWForge = (() => {
4968
5130
  this.videos = /* @__PURE__ */ new Map();
4969
5131
  }
4970
5132
  static async create(options) {
5133
+ var _a, _b;
4971
5134
  const { bridge } = await ForgeRuntimeBridge.create(options);
4972
5135
  const forge = new _NPAWForge(bridge);
4973
5136
  if (options.startSessionOnInitialize) {
@@ -4975,9 +5138,23 @@ var NPAWForge = (() => {
4975
5138
  }
4976
5139
  forge.captureHandle = installCapture(forge, options.capture);
4977
5140
  forge.capturePlanUnsubscribe = bridge.onCapturePlan((plan) => {
4978
- var _a, _b;
4979
- (_b = (_a = forge.captureHandle) == null ? void 0 : _a.applyPlan) == null ? void 0 : _b.call(_a, plan);
5141
+ var _a2, _b2;
5142
+ (_b2 = (_a2 = forge.captureHandle) == null ? void 0 : _a2.applyPlan) == null ? void 0 : _b2.call(_a2, plan);
4980
5143
  });
5144
+ if ((_a = options.autoLocation) != null ? _a : true) {
5145
+ forge.locationObserver = new ForgeLocationObserver((fix) => {
5146
+ void forge.recordLocationFix(fix);
5147
+ });
5148
+ bridge.onCapturePlan((plan) => {
5149
+ forge.applyLocationPlan(plan);
5150
+ });
5151
+ }
5152
+ if ((_b = options.autoConnectionType) != null ? _b : true) {
5153
+ forge.connectionTypeObserver = new ForgeConnectionTypeObserver((connectionType) => {
5154
+ void forge.setAutoConnectionType(connectionType);
5155
+ });
5156
+ forge.connectionTypeObserver.start();
5157
+ }
4981
5158
  return forge;
4982
5159
  }
4983
5160
  onEvent(listener) {
@@ -5143,6 +5320,40 @@ var NPAWForge = (() => {
5143
5320
  setLogLevel(level) {
5144
5321
  return this.runtime.process({ type: "setLogLevel", level });
5145
5322
  }
5323
+ /**
5324
+ * Reports the browser's current connection class to the kernel. Called by the
5325
+ * automatic observer; a `connectionType` set through video metadata keeps
5326
+ * precedence over it.
5327
+ */
5328
+ setAutoConnectionType(connectionType) {
5329
+ return this.runtime.process({ type: "setAutoConnectionType", connectionType });
5330
+ }
5331
+ /** Forwards a location fix to the kernel, which owns every threshold. */
5332
+ recordLocationFix(fix) {
5333
+ return this.runtime.process({
5334
+ type: "recordLocationFix",
5335
+ latitude: fix.latitude,
5336
+ longitude: fix.longitude,
5337
+ accuracyM: fix.accuracyMetres,
5338
+ timestampMs: fix.timestampMs
5339
+ });
5340
+ }
5341
+ /**
5342
+ * Starts or stops location observation to match the capture plan. Nothing is
5343
+ * observed - not even the permission state - until an operator enables one
5344
+ * of the two motion switches.
5345
+ */
5346
+ applyLocationPlan(plan) {
5347
+ const observer = this.locationObserver;
5348
+ if (!observer) {
5349
+ return;
5350
+ }
5351
+ if ((plan.bits & CAPTURE_PLAN_BITS.LOCATION) !== 0) {
5352
+ void observer.start();
5353
+ } else {
5354
+ observer.stop();
5355
+ }
5356
+ }
5146
5357
  applicationForeground(foreground) {
5147
5358
  return this.runtime.process({
5148
5359
  type: "applicationForeground",
@@ -5196,7 +5407,7 @@ var NPAWForge = (() => {
5196
5407
  return (_b = video == null ? void 0 : video.removeAdAdapter()) != null ? _b : false;
5197
5408
  }
5198
5409
  async destroy() {
5199
- var _a, _b;
5410
+ var _a, _b, _c, _d;
5200
5411
  for (const video of this.videos.values()) {
5201
5412
  video.detach();
5202
5413
  }
@@ -5206,6 +5417,10 @@ var NPAWForge = (() => {
5206
5417
  this.capturePlanUnsubscribe = void 0;
5207
5418
  (_b = this.captureHandle) == null ? void 0 : _b.dispose();
5208
5419
  this.captureHandle = void 0;
5420
+ (_c = this.connectionTypeObserver) == null ? void 0 : _c.stop();
5421
+ this.connectionTypeObserver = void 0;
5422
+ (_d = this.locationObserver) == null ? void 0 : _d.stop();
5423
+ this.locationObserver = void 0;
5209
5424
  return this.runtime.destroy();
5210
5425
  }
5211
5426
  whenIdle() {