@needle-tools/engine 4.12.0-next.c6c0281 → 4.12.0-next.da19dd0

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.
Files changed (87) hide show
  1. package/dist/generateMeshBVH.worker-iyfPIK6R.js +21 -0
  2. package/dist/needle-engine.bundle-BoOkD4mG.umd.cjs +1647 -0
  3. package/dist/{needle-engine.bundle-ThW_g39D.min.js → needle-engine.bundle-DDdH38o3.min.js} +151 -150
  4. package/dist/{needle-engine.bundle-BVdPECIB.js → needle-engine.bundle-DeqWDtMx.js} +8997 -8592
  5. package/dist/needle-engine.d.ts +27 -18
  6. package/dist/needle-engine.js +46 -46
  7. package/dist/needle-engine.min.js +1 -1
  8. package/dist/needle-engine.umd.cjs +1 -1
  9. package/dist/{vendor-C_oHRUjX.js → vendor-DMZcbVO1.js} +2644 -2487
  10. package/dist/{vendor-BiJQtqow.min.js → vendor-sURMCFSI.min.js} +41 -41
  11. package/dist/{vendor-DN-NsXVB.umd.cjs → vendor-tyBvnMF-.umd.cjs} +36 -36
  12. package/lib/engine/debug/debug_console.js +403 -1
  13. package/lib/engine/debug/debug_console.js.map +1 -1
  14. package/lib/engine/engine_components.js +3 -3
  15. package/lib/engine/engine_components.js.map +1 -1
  16. package/lib/engine/engine_context.js +2 -0
  17. package/lib/engine/engine_context.js.map +1 -1
  18. package/lib/engine/engine_input.d.ts +5 -0
  19. package/lib/engine/engine_input.js +6 -0
  20. package/lib/engine/engine_input.js.map +1 -1
  21. package/lib/engine/engine_license.d.ts +18 -0
  22. package/lib/engine/engine_license.js +155 -9
  23. package/lib/engine/engine_license.js.map +1 -1
  24. package/lib/engine/engine_networking.js +5 -5
  25. package/lib/engine/engine_networking.js.map +1 -1
  26. package/lib/engine/engine_physics.js.map +1 -1
  27. package/lib/engine/engine_serialization_builtin_serializer.js +1 -1
  28. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  29. package/lib/engine/engine_utils.d.ts +4 -1
  30. package/lib/engine/engine_utils.js +28 -4
  31. package/lib/engine/engine_utils.js.map +1 -1
  32. package/lib/engine/webcomponents/WebXRButtons.js +13 -5
  33. package/lib/engine/webcomponents/WebXRButtons.js.map +1 -1
  34. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +2 -0
  35. package/lib/engine/webcomponents/needle menu/needle-menu.js +33 -1
  36. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  37. package/lib/engine/webcomponents/needle-engine.ar-overlay.js +4 -0
  38. package/lib/engine/webcomponents/needle-engine.ar-overlay.js.map +1 -1
  39. package/lib/engine/xr/NeedleXRSession.d.ts +1 -1
  40. package/lib/engine/xr/NeedleXRSession.js +106 -22
  41. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  42. package/lib/engine/xr/TempXRContext.js +12 -2
  43. package/lib/engine/xr/TempXRContext.js.map +1 -1
  44. package/lib/engine/xr/usdz.js +6 -2
  45. package/lib/engine/xr/usdz.js.map +1 -1
  46. package/lib/engine-components/Camera.js +4 -1
  47. package/lib/engine-components/Camera.js.map +1 -1
  48. package/lib/engine-components/Component.d.ts +2 -1
  49. package/lib/engine-components/Component.js +3 -2
  50. package/lib/engine-components/Component.js.map +1 -1
  51. package/lib/engine-components/DragControls.js +1 -1
  52. package/lib/engine-components/DragControls.js.map +1 -1
  53. package/lib/engine-components/SpectatorCamera.js +15 -7
  54. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  55. package/lib/engine-components/api.d.ts +1 -1
  56. package/lib/engine-components/api.js +1 -1
  57. package/lib/engine-components/api.js.map +1 -1
  58. package/lib/engine-components/webxr/Avatar.js +2 -0
  59. package/lib/engine-components/webxr/Avatar.js.map +1 -1
  60. package/lib/engine-components/webxr/WebXR.js +18 -12
  61. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  62. package/package.json +3 -3
  63. package/plugins/vite/poster-client.js +8 -1
  64. package/src/engine/debug/debug_console.ts +449 -1
  65. package/src/engine/engine_components.ts +4 -4
  66. package/src/engine/engine_context.ts +2 -0
  67. package/src/engine/engine_input.ts +7 -0
  68. package/src/engine/engine_license.ts +171 -9
  69. package/src/engine/engine_networking.ts +5 -5
  70. package/src/engine/engine_physics.ts +3 -3
  71. package/src/engine/engine_serialization_builtin_serializer.ts +1 -1
  72. package/src/engine/engine_utils.ts +23 -4
  73. package/src/engine/webcomponents/WebXRButtons.ts +15 -5
  74. package/src/engine/webcomponents/needle menu/needle-menu.ts +35 -2
  75. package/src/engine/webcomponents/needle-engine.ar-overlay.ts +6 -0
  76. package/src/engine/xr/NeedleXRSession.ts +120 -24
  77. package/src/engine/xr/TempXRContext.ts +12 -2
  78. package/src/engine/xr/usdz.ts +6 -1
  79. package/src/engine-components/Camera.ts +4 -1
  80. package/src/engine-components/Component.ts +5 -4
  81. package/src/engine-components/DragControls.ts +1 -1
  82. package/src/engine-components/SpectatorCamera.ts +21 -10
  83. package/src/engine-components/api.ts +1 -1
  84. package/src/engine-components/webxr/Avatar.ts +4 -0
  85. package/src/engine-components/webxr/WebXR.ts +19 -11
  86. package/dist/generateMeshBVH.worker-BvGEI0r7.js +0 -21
  87. package/dist/needle-engine.bundle-Dk2U2sIu.umd.cjs +0 -1646
@@ -1,9 +1,13 @@
1
+ import { dof } from "three/src/nodes/TSL.js";
1
2
  import { isDevEnvironment } from "./debug/index.js";
2
3
  import { BUILD_TIME, GENERATOR, PUBLIC_KEY, VERSION } from "./engine_constants.js";
3
4
  import { ContextEvent, ContextRegistry } from "./engine_context_registry.js";
5
+ import { onInitialized } from "./engine_lifecycle_api.js";
6
+ import { isLocalNetwork } from "./engine_networking_utils.js";
4
7
  import { Context } from "./engine_setup.js";
5
8
  import type { IContext } from "./engine_types.js";
6
9
  import { getParam } from "./engine_utils.js";
10
+ import { InternalAttributeUtils } from "./engine_utils_attributes.js";
7
11
 
8
12
  const debug = getParam("debuglicense");
9
13
 
@@ -67,6 +71,169 @@ function invokeLicenseCheckResultChanged(result: boolean) {
67
71
  }
68
72
  }
69
73
 
74
+
75
+
76
+ // #region Telemetry
77
+ export namespace Telemetry {
78
+
79
+ window.addEventListener("error", (event: ErrorEvent) => {
80
+ sendError(Context.Current, "unhandled_error", event);
81
+ });
82
+ window.addEventListener("unhandledrejection", (event: PromiseRejectionEvent) => {
83
+ sendError(Context.Current, "unhandled_promise_rejection", {
84
+ message: event.reason?.message,
85
+ stack: event.reason?.stack,
86
+ timestamp: Date.now(),
87
+ });
88
+ });
89
+
90
+ onInitialized((ctx => sendPageViewEvent(ctx)), { once: true });
91
+
92
+ function sendPageViewEvent(ctx: IContext) {
93
+ if (!isAllowed(ctx)) {
94
+ if (debug) console.debug("Telemetry is disabled via no-telemetry attribute");
95
+ return;
96
+ }
97
+ return doFetch({
98
+ site_id: "dabb8317376f",
99
+ type: "pageview",
100
+ pathname: window.location.pathname,
101
+ hostname: window.location.hostname,
102
+ page_title: document.title,
103
+ referrer: document.referrer,
104
+ user_agent: navigator.userAgent,
105
+ querystring: window.location.search,
106
+ language: navigator.language,
107
+ screenWidth: window.screen.width,
108
+ screenHeight: window.screen.height,
109
+ event_name: "page_view"
110
+ }).then(res => {
111
+ if (res instanceof Response && res.ok && isLocalNetwork()) {
112
+ sendEvent(ctx, "info", {
113
+ src: ctx.domElement?.getAttribute("src") || "",
114
+ version: VERSION,
115
+ generator: GENERATOR,
116
+ build_time: BUILD_TIME,
117
+ public_key: PUBLIC_KEY,
118
+ });
119
+ }
120
+ })
121
+ }
122
+
123
+ export function isAllowed(context: IContext | null | undefined): boolean {
124
+ let domElement = context?.domElement as HTMLElement | null;
125
+ if (!domElement) domElement = document.querySelector<HTMLElement>("needle-engine");
126
+ if (!domElement && !context) return false;
127
+
128
+ const attribute = domElement?.getAttribute("no-telemetry");
129
+ if (attribute === "" || attribute === "true" || attribute === "1") {
130
+ if (NEEDLE_ENGINE_LICENSE_TYPE === "pro" || NEEDLE_ENGINE_LICENSE_TYPE === "enterprise") {
131
+ if (debug) console.debug("Telemetry is disabled via no-telemetry attribute");
132
+ return false;
133
+ }
134
+ }
135
+ return true;
136
+ }
137
+
138
+ const id = "dabb8317376f";
139
+
140
+ /**
141
+ * Sends a telemetry event
142
+ */
143
+ export async function sendEvent(context: IContext | null | undefined, eventName: string, properties?: Record<string, any>) {
144
+ if (!isAllowed(context)) {
145
+ if (debug) console.debug("Telemetry is disabled");
146
+ return;
147
+ }
148
+ const body = {
149
+ site_id: id,
150
+ type: "custom_event",
151
+ pathname: window.location.pathname,
152
+ event_name: eventName,
153
+ properties: properties ? JSON.stringify(properties) : undefined,
154
+ }
155
+ return doFetch(body);
156
+ }
157
+
158
+ type ErrorData = {
159
+ message?: string;
160
+ stack?: string;
161
+ filename?: string;
162
+ lineno?: number;
163
+ colno?: number;
164
+ timestamp?: number;
165
+ }
166
+
167
+ export async function sendError(context: IContext, errorName: string, error: ErrorData | ErrorEvent | Error) {
168
+
169
+ if (!isAllowed(context)) {
170
+ if (debug) console.debug("Telemetry is disabled");
171
+ return;
172
+ }
173
+
174
+ if (error instanceof ErrorEvent) {
175
+ error = {
176
+ message: error.message,
177
+ stack: error.error?.stack,
178
+ filename: error.filename,
179
+ lineno: error.lineno,
180
+ colno: error.colno,
181
+ timestamp: error.timeStamp || Date.now(),
182
+
183
+ };
184
+ }
185
+ else if (error instanceof Error) {
186
+ error = {
187
+ message: error.message,
188
+ stack: error.stack,
189
+ timestamp: Date.now(),
190
+ };
191
+ }
192
+ const body = {
193
+ site_id: id,
194
+ type: "error",
195
+ event_name: errorName || "error",
196
+ properties: JSON.stringify({
197
+ error_name: errorName,
198
+ message: error.message,
199
+ stack: error.stack,
200
+ filename: error.filename,
201
+ lineno: error.lineno,
202
+ colno: error.colno,
203
+ timestamp: error.timestamp,
204
+ })
205
+ }
206
+ return doFetch(body);
207
+ }
208
+
209
+ function doFetch(body: Record<string, any>) {
210
+ try {
211
+ const url = "https://needle.tools/api/v1/rum/t";
212
+ return fetch(url, {
213
+ method: "POST",
214
+ body: JSON.stringify(body),
215
+ headers: {
216
+ 'Content-Type': 'application/json'
217
+ },
218
+ // Ensures request completes even if page unloads
219
+ keepalive: true,
220
+ // Allow CORS requests
221
+ mode: 'cors',
222
+ // Low priority to avoid blocking other requests
223
+ // @ts-ignore
224
+ priority: 'low',
225
+ }).catch(e => {
226
+ if (debug) console.error("Failed to send telemetry", e);
227
+ })
228
+ }
229
+ catch (err) {
230
+ if (debug) console.error(err);
231
+ }
232
+ return Promise.resolve();
233
+ }
234
+ }
235
+
236
+
70
237
  ContextRegistry.registerCallback(ContextEvent.ContextRegistered, evt => {
71
238
  showLicenseInfo(evt.context);
72
239
  handleForbidden(evt.context);
@@ -341,14 +508,9 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
341
508
  // We can't send beacons from cross-origin isolated pages
342
509
  if (window.crossOriginIsolated) return;
343
510
 
344
- const licenseType = NEEDLE_ENGINE_LICENSE_TYPE;
345
- if (licenseType === "pro" || licenseType === "enterprise") {
346
- const attribute = context?.domElement?.getAttribute("no-telemetry");
347
- if (attribute === "" || attribute === "true" || attribute === "1") {
348
- if (debug) console.debug("Telemetry is disabled");
349
- return;
350
- }
351
- if (debug) console.debug("Telemetry attribute: " + attribute);
511
+ if (!Telemetry.isAllowed(context)) {
512
+ if (debug) console.debug("Telemetry is disabled via no-telemetry attribute");
513
+ return;
352
514
  }
353
515
 
354
516
  try {
@@ -379,4 +541,4 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
379
541
  if (debug)
380
542
  console.log("Failed to send non-commercial usage message to analytics backend", err);
381
543
  }
382
- }
544
+ }
@@ -629,7 +629,7 @@ export class NetworkConnection implements INetworkConnection {
629
629
  return;
630
630
  }
631
631
 
632
- console.debug("Connecting to networking backend on\n" + networkingServerUrl)
632
+ console.debug("Connecting to networking backend on\n" + networkingServerUrl)
633
633
  const pkg = await import('websocket-ts');
634
634
  // @ts-ignore
635
635
  const WebsocketBuilder = pkg.default?.WebsocketBuilder ?? pkg.WebsocketBuilder;
@@ -641,8 +641,8 @@ export class NetworkConnection implements INetworkConnection {
641
641
  this._connectingToWebsocketPromise = null;
642
642
  this._ws = ws;
643
643
  this.connected = true;
644
- if (isDevEnvironment() || debugNet) console.log("Connected to networking backend\n" + networkingServerUrl);
645
- else console.debug("Connected to networking backend", networkingServerUrl);
644
+ if (isDevEnvironment() || debugNet) console.log("Connected to networking backend\n" + networkingServerUrl);
645
+ else console.debug("Connected to networking backend", networkingServerUrl);
646
646
  resolve(true);
647
647
  this.onSendQueued(SendQueue.OnConnection);
648
648
  })
@@ -656,10 +656,10 @@ export class NetworkConnection implements INetworkConnection {
656
656
  console.error(msg);
657
657
  })
658
658
  .onError((_e) => {
659
- console.error("Websocket connection failed...");
659
+ console.error("Websocket connection failed...");
660
660
  resolve(false);
661
661
  })
662
- .onRetry(() => { console.log("Retry connecting to networking websocket") })
662
+ .onRetry(() => { console.log("Retry connecting to networking websocket") })
663
663
  .build();
664
664
  ws.addEventListener(pkg.WebsocketEvent.message, (socket, msg) => {
665
665
  this.onMessage(socket, msg);
@@ -1,7 +1,7 @@
1
1
  import { getRaycastMesh } from '@needle-tools/gltf-progressive';
2
2
  import { ArrayCamera, Box3, BufferGeometry, Camera, type Intersection, Layers, Line, Matrix3, Matrix4, Mesh, Object3D, PerspectiveCamera, Plane, Ray, Raycaster, SkinnedMesh, Sphere, SphereGeometry, Vector2, Vector3 } from 'three'
3
3
  import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
4
- import type { MeshBVH, MeshBVHOptions, StaticGeometryGenerator } from 'three-mesh-bvh';
4
+ import type { ComputeBVHOptions, GeometryBVH, MeshBVH, StaticGeometryGenerator } from 'three-mesh-bvh';
5
5
  import type { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
6
6
 
7
7
  import { isDevEnvironment } from './debug/index.js';
@@ -762,7 +762,7 @@ namespace NEMeshBVH {
762
762
  return true;
763
763
  }
764
764
  else if (method instanceof Sphere) {
765
- const bvh = geom.boundsTree;
765
+ const bvh = geom.boundsTree as MeshBVH | undefined;
766
766
  if (bvh) {
767
767
  const sphere = method;
768
768
  // Gizmos.DrawWireSphere(sphere.center, sphere.radius, 0xdddd00, 1, false);
@@ -789,7 +789,7 @@ namespace NEMeshBVH {
789
789
  let _acceleratedRaycast: Function | null = null;
790
790
  let _MeshBVH: ConstructorConcrete<MeshBVH> | null = null;
791
791
  let _StaticGeometryGenerator: ConstructorConcrete<StaticGeometryGenerator> | null = null;
792
- let _computeBoundsTree: ((_opt?: MeshBVHOptions) => MeshBVH) | null = null;
792
+ let _computeBoundsTree: (( options?: ComputeBVHOptions ) => GeometryBVH) | null = null;
793
793
 
794
794
  function loadMeshBVHLibrary() {
795
795
  if (didLoadMeshBVHLibrary) return;
@@ -337,7 +337,7 @@ class EventListSerializer extends TypeSerializer {
337
337
  args = call.arguments.map(deserializeArgument);
338
338
  }
339
339
  const method = target[call.method];
340
- if (!method) {
340
+ if (method === undefined) {
341
341
  console.warn(`EventList method not found: \"${call.method}\" on ${target?.name}`);
342
342
  }
343
343
  else {
@@ -606,7 +606,8 @@ export namespace DeviceUtilities {
606
606
  /** @returns `true` if we're currently on an iPad */
607
607
  export function isiPad() {
608
608
  if (__isiPad !== undefined) return __isiPad;
609
- return __isiPad = /iPad/.test(navigator.userAgent);
609
+ const userAgent = navigator.userAgent.toLowerCase();
610
+ return __isiPad = /iPad/.test(navigator.userAgent) || userAgent.includes("macintosh") && "ontouchend" in document;
610
611
  }
611
612
 
612
613
  let __isAndroidDevice: boolean | undefined;
@@ -623,17 +624,25 @@ export namespace DeviceUtilities {
623
624
  return __isMozillaXR = /WebXRViewer\//i.test(navigator.userAgent);
624
625
  }
625
626
 
627
+ let __isNeedleAppClip: boolean | undefined;
628
+ /** @returns `true` if we're currently in the Needle App Clip */
629
+ export function isNeedleAppClip() {
630
+ if (__isNeedleAppClip !== undefined) return __isNeedleAppClip;
631
+ return __isNeedleAppClip = /NeedleAppClip\//i.test(navigator.userAgent);
632
+ }
633
+
626
634
  let __isMacOS: boolean | undefined;
627
635
  // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgentData
628
636
  /** @returns `true` for MacOS devices */
629
637
  export function isMacOS() {
630
638
  if (__isMacOS !== undefined) return __isMacOS;
639
+ if (isiOS() || isiPad()) return __isMacOS = false;
640
+ const userAgent = navigator.userAgent.toLowerCase();
631
641
  if (navigator.userAgentData) {
632
642
  // Use modern UA Client Hints API if available
633
643
  return __isMacOS = navigator.userAgentData.platform === 'macOS';
634
644
  } else {
635
645
  // Fallback to user agent string parsing
636
- const userAgent = navigator.userAgent.toLowerCase();
637
646
  return __isMacOS = userAgent.includes('mac os x') || userAgent.includes('macintosh');
638
647
  }
639
648
  }
@@ -642,13 +651,13 @@ export namespace DeviceUtilities {
642
651
  /** @returns `true` for VisionOS devices */
643
652
  export function isVisionOS() {
644
653
  if (__isVisionOS !== undefined) return __isVisionOS;
645
- return __isVisionOS = (isMacOS() && "xr" in navigator);
654
+ return __isVisionOS = (isiPad() && "xr" in navigator && supportsQuickLookAR());
646
655
  }
647
656
 
648
657
  let __isiOS: boolean | undefined;
649
658
  const iosDevices = ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'];
650
659
 
651
- /** @returns `true` for iOS devices like iPad, iPhone, iPod... */
660
+ /** @returns `true` for mobile Apple devices like iPad, iPhone, iPod, Vision Pro, ... */
652
661
  export function isiOS() {
653
662
  if (__isiOS !== undefined) return __isiOS;
654
663
  // eslint-disable-next-line deprecation/deprecation
@@ -725,6 +734,16 @@ export namespace DeviceUtilities {
725
734
  else __chromeVersion = null;
726
735
  return __chromeVersion;
727
736
  }
737
+
738
+ let __safariVersion: string | null | undefined;
739
+ export function getSafariVersion() {
740
+ if (__safariVersion !== undefined) return __safariVersion;
741
+ const match = navigator.userAgent.match(/Version\/(\d+\.\d+)/);
742
+ if (match && isSafari()) {
743
+ __safariVersion = match[1];
744
+ } else __safariVersion = null;
745
+ return __safariVersion;
746
+ }
728
747
  }
729
748
 
730
749
  /**
@@ -57,13 +57,16 @@ export class WebXRButtonFactory {
57
57
  this._quicklookButton = button;
58
58
  button.dataset["needle"] = "quicklook-button";
59
59
  const supportsQuickLook = DeviceUtilities.supportsQuickLookAR();
60
+ let buttonText = "View in AR";
60
61
  // we can immediately enter this scene, because the platform supports rel="ar" links
61
- if (supportsQuickLook) {
62
- button.innerText = "View in AR";
62
+ if (DeviceUtilities.isVisionOS()) {
63
+ buttonText = "View in AR";
63
64
  }
64
- else {
65
- button.innerText = "View in AR";
65
+ else if (supportsQuickLook || DeviceUtilities.isiOS()) {
66
+ buttonText = "Open in Quicklook";
66
67
  }
68
+
69
+ button.innerText = buttonText;
67
70
  button.prepend(getIconElement("view_in_ar"));
68
71
 
69
72
  let createdExporter = false;
@@ -209,13 +212,20 @@ export class WebXRButtonFactory {
209
212
  }
210
213
 
211
214
  private updateSessionSupported(button: HTMLButtonElement, mode: XRSessionMode) {
215
+ if (mode === "immersive-ar" && DeviceUtilities.isiOS() && !DeviceUtilities.isVisionOS()) {
216
+ // on iOS, we can forward to the AppClip experience from the same button,
217
+ // so we always show the button. No AppClip support on VisionOS for now, so
218
+ // button state depends on WebXR support there.
219
+ return;
220
+ }
221
+
212
222
  if (!("xr" in navigator)) {
213
223
  button.style.display = "none";
214
224
  return;
215
225
  }
216
226
  NeedleXRSession.isSessionSupported(mode).then(supported => {
217
227
  button.style.display = !supported ? "none" : "";
218
- if (isDevEnvironment() && !supported) console.log("[WebXR] \"" + mode + "\" is not supported on this device make sure your server runs using HTTPS and you have a device connected that supports " + mode);
228
+ if (isDevEnvironment() && !supported) console.log("[WebXR] \"" + mode + "\" is not supported on this device. Make sure your server runs using HTTPS and you have a device connected that supports " + mode);
219
229
  });
220
230
  }
221
231
 
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "../../engine_context.js";
2
- import { hasCommercialLicense, onLicenseCheckResultChanged } from "../../engine_license.js";
2
+ import { hasCommercialLicense, onLicenseCheckResultChanged, Telemetry } from "../../engine_license.js";
3
3
  import { isLocalNetwork } from "../../engine_networking_utils.js";
4
4
  import { DeviceUtilities, getParam } from "../../engine_utils.js";
5
5
  import { onXRSessionStart, XRSessionEventArgs } from "../../xr/events.js";
@@ -149,6 +149,9 @@ export class NeedleMenu {
149
149
  else console.error("NeedleMenu: onclick is not a valid link", buttoninfo.onclick);
150
150
  }
151
151
  }
152
+ Telemetry.sendEvent(this._context, "needle-menu", {
153
+ action: "button_added_via_postmessage",
154
+ });
152
155
  this._menu.appendChild(button);
153
156
  }
154
157
  else if (debug) console.error("NeedleMenu: unknown postMessage event", data);
@@ -935,12 +938,39 @@ export class NeedleMenuElement extends HTMLElement {
935
938
  /** @private foldout container used in compact mode */
936
939
  private readonly foldout: HTMLDivElement;
937
940
 
941
+
942
+ private readonly trackedElements: WeakSet<Node> = new WeakSet();
943
+ private trackElement(el: Node) {
944
+ if (this.trackedElements.has(el)) return;
945
+ this.trackedElements.add(el);
946
+ el.addEventListener("click", (evt) => {
947
+ Telemetry.sendEvent(this._context, "needle-menu", {
948
+ action: "button_clicked",
949
+ element: evt.target instanceof Node ? evt.target.nodeName : el.nodeName,
950
+ label: el.textContent,
951
+ title: (el instanceof HTMLElement) ? el.title : undefined,
952
+ pointerid: (evt instanceof PointerEvent) ? evt.pointerId : undefined,
953
+ });
954
+ });
955
+ // el.addEventListener("pointerenter", (evt) => {
956
+ // Telemetry.sendEvent(this._context, "needle-menu", {
957
+ // action: "button_hovered",
958
+ // element: evt.target instanceof Node ? evt.target.nodeName : el.nodeName,
959
+ // label: el.textContent,
960
+ // title: (el instanceof HTMLElement) ? el.title : undefined,
961
+ // pointerid: (evt instanceof PointerEvent) ? evt.pointerId : undefined,
962
+ // });
963
+ // });
964
+ }
965
+
938
966
  append(...nodes: (string | Node)[]): void {
939
967
  for (const node of nodes) {
940
968
  if (typeof node === "string") {
941
969
  const element = document.createTextNode(node);
970
+ this.trackElement(element);
942
971
  this.options.appendChild(element);
943
972
  } else {
973
+ this.trackElement(node);
944
974
  this.options.appendChild(node);
945
975
  }
946
976
  }
@@ -987,9 +1017,10 @@ export class NeedleMenuElement extends HTMLElement {
987
1017
  if (node.class) {
988
1018
  button.classList.add(node.class);
989
1019
  }
1020
+
990
1021
  node = button as unknown as T;
991
1022
  }
992
-
1023
+ this.trackElement(node);
993
1024
  const res = this.options.appendChild(node);
994
1025
  return res;
995
1026
  }
@@ -997,8 +1028,10 @@ export class NeedleMenuElement extends HTMLElement {
997
1028
  for (const node of nodes) {
998
1029
  if (typeof node === "string") {
999
1030
  const element = document.createTextNode(node);
1031
+ this.trackElement(element);
1000
1032
  this.options.prepend(element);
1001
1033
  } else {
1034
+ this.trackElement(node);
1002
1035
  this.options.prepend(node);
1003
1036
  }
1004
1037
  }
@@ -118,6 +118,12 @@ export class AROverlayHandler {
118
118
  }
119
119
 
120
120
  private ensureQuitARButton(element: HTMLElement) {
121
+
122
+ // No quit button in app clips, we provide one via the native UI
123
+ if (DeviceUtilities.isNeedleAppClip()) {
124
+ return;
125
+ }
126
+
121
127
  const quitARSlot = document.createElement("slot");
122
128
  quitARSlot.setAttribute("name", "quit-ar");
123
129
  this.appendElement(quitARSlot, element);