@webspatial/platform-visionos 0.1.16 → 0.1.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webspatial/platform-visionos",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Used to publish WebSpatial projects to Apple Vision Pro",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -11,7 +11,7 @@ class SpatialComponent: SpatialObject {
11
11
 
12
12
  override func inspect() -> [String: Any] {
13
13
  var inspectInfo: [String: Any] = [
14
- "entity": entity?.id,
14
+ "entity": entity == nil ? "invalid" : entity!.id,
15
15
  "type": String(describing: type(of: self)),
16
16
  ]
17
17
 
@@ -7,10 +7,12 @@ struct SpatialObjectInfo: Codable {
7
7
  var entityArray: [String]
8
8
  }
9
9
 
10
+ // Stats from native code. Objects tracks number of native objects that were created but not yet explicitly destroyed. RefObjects tracks bjects that still have references. After an object is destroyed, we should be cleaning up all of the native references. Expect objects.count == refObjects.count , if not, there is likely a leak.
10
11
  struct SpatialObjectStatsInfo: Codable {
11
12
  var backend = "AVP"
12
13
  var objects: SpatialObjectInfo
13
14
  var refObjects: SpatialObjectInfo
15
+ var perfStats: PerfStats
14
16
  }
15
17
 
16
18
  class WeakReference<T: AnyObject> {
@@ -70,7 +72,8 @@ class SpatialObject: EventEmitter, Equatable {
70
72
  windowArray: Array(weakRefWebviews.keys),
71
73
  windowContainerArray: Array(weakRefWindowContainers.keys),
72
74
  entityArray: Array(weakRefEntities.keys)
73
- )
75
+ ),
76
+ perfStats: clock.perfStats
74
77
  )
75
78
  }
76
79
 
@@ -456,6 +456,7 @@ class CommandManager {
456
456
  spatialWindowComponent.getView()!.destroy()
457
457
  spatialWindowComponent.setView(wv: spawnedWebView)
458
458
  spatialWindowComponent.getView()!.webViewHolder.webViewCoordinator!.webViewRef = spatialWindowComponent
459
+ spatialWindowComponent.didFinishFirstLoad = true
459
460
  }
460
461
  }
461
462
 
@@ -492,6 +493,8 @@ class CommandManager {
492
493
  }
493
494
 
494
495
  if let backgroundMaterial: BackgroundMaterial = data.update?.style?.backgroundMaterial {
496
+ clock.backgroundSet()
497
+
495
498
  if spatialWindowComponent.isLoading {
496
499
  spatialWindowComponent.loadingStyles.backgroundMaterial = backgroundMaterial
497
500
  }
@@ -523,7 +526,7 @@ class CommandManager {
523
526
 
524
527
  // If the parent window component isn't set, the new container can continue to exist even after other window is closed
525
528
  if info.resourceID != "notFound" {
526
- var rid = info.resourceID
529
+ let rid = info.resourceID
527
530
  let so = SpatialObject.get(rid)
528
531
  if let parentWindowComponent = so as? SpatialWindowComponent {
529
532
  parentWindowComponent.setWindowContainer(uuid: uuid, wgd: wgd)
@@ -531,7 +534,7 @@ class CommandManager {
531
534
  }
532
535
 
533
536
  if info.windowContainerID != "notFound" {
534
- if var parentContainer = SpatialWindowContainer.getSpatialWindowContainer(info.windowContainerID) {
537
+ if let parentContainer = SpatialWindowContainer.getSpatialWindowContainer(info.windowContainerID) {
535
538
  parentContainer.childContainers[uuid] = wg
536
539
  }
537
540
  }
@@ -0,0 +1,43 @@
1
+ import SwiftUI
2
+
3
+ struct PerfStats: Codable {
4
+ // Time from app start until the first call to setMaterial. In milliseconds
5
+ var firstBackgroundSet: Int = 0
6
+
7
+ // Attempts to track the number of commands handled over the last second
8
+ var commandCounter: Int = 0
9
+ var commandCounterStartTime: Int = 0
10
+ var commandsPerSecond = 0.0
11
+ }
12
+
13
+ class PerfClock {
14
+ var perfStats = PerfStats()
15
+
16
+ let createTimeMS: Int
17
+
18
+ init() {
19
+ createTimeMS = PerfClock.getCurrentTimeMS()
20
+ perfStats.commandCounterStartTime = createTimeMS
21
+ }
22
+
23
+ func backgroundSet() {
24
+ if perfStats.firstBackgroundSet == 0 {
25
+ perfStats.firstBackgroundSet = PerfClock.getCurrentTimeMS() - createTimeMS
26
+ }
27
+ }
28
+
29
+ func onMessage() {
30
+ perfStats.commandCounter += 1
31
+ let dt = PerfClock.getCurrentTimeMS() - createTimeMS
32
+ if dt > 1000 {
33
+ perfStats.commandsPerSecond = Double(perfStats.commandCounter) / (Double(1000.0) / Double(dt))
34
+
35
+ perfStats.commandCounter = 0
36
+ perfStats.commandCounterStartTime = PerfClock.getCurrentTimeMS()
37
+ }
38
+ }
39
+
40
+ static func getCurrentTimeMS() -> Int {
41
+ return Int(Date().timeIntervalSince1970 * 1000)
42
+ }
43
+ }
@@ -48,10 +48,12 @@ class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUID
48
48
  return
49
49
  }
50
50
  let session = URLSession(configuration: URLSessionConfiguration.default)
51
- let dataTask = session.dataTask(with: urlRequest) { data, response, _ in
52
- urlSchemeTask.didReceive(response!)
53
- urlSchemeTask.didReceive(data!)
54
- urlSchemeTask.didFinish()
51
+ let dataTask = session.dataTask(with: urlRequest) { [task = urlSchemeTask as AnyObject] data, response, _ in
52
+ guard let task = task as? WKURLSchemeTask else { return }
53
+
54
+ task.didReceive(response!)
55
+ task.didReceive(data!)
56
+ task.didFinish()
55
57
  }
56
58
  dataTask.resume()
57
59
  return
@@ -7,6 +7,7 @@ import typealias RealityKit.RealityView
7
7
  import typealias RealityKit.SimpleMaterial
8
8
  import SwiftUI
9
9
 
10
+ let clock = PerfClock()
10
11
  let logger = Logger()
11
12
 
12
13
  // To load a local path, remove http:// eg. "static-web/"
@@ -9,6 +9,7 @@
9
9
  /* Begin PBXBuildFile section */
10
10
  2B0B1C102C494E5400E644F9 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B0B1C0F2C494E5400E644F9 /* Logger.swift */; };
11
11
  2B0B430A2CBE21580003CEF3 /* CommandManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B0B43092CBE21540003CEF3 /* CommandManager.swift */; };
12
+ 2B0FF4F42DD2711E00C3F20A /* PerfClock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B0FF4F32DD2711800C3F20A /* PerfClock.swift */; };
12
13
  2B23CB3F2D0BEE6900E70D95 /* WindowContainerMgr.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B23CB3E2D0BEE6900E70D95 /* WindowContainerMgr.swift */; };
13
14
  2B2F1D692BEBFAAA006897EE /* RealityKitContent in Frameworks */ = {isa = PBXBuildFile; productRef = 2B2F1D682BEBFAAA006897EE /* RealityKitContent */; };
14
15
  2B2F1D6B2BEBFAAA006897EE /* web_spatialApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B2F1D6A2BEBFAAA006897EE /* web_spatialApp.swift */; };
@@ -60,6 +61,7 @@
60
61
  /* Begin PBXFileReference section */
61
62
  2B0B1C0F2C494E5400E644F9 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
62
63
  2B0B43092CBE21540003CEF3 /* CommandManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandManager.swift; sourceTree = "<group>"; };
64
+ 2B0FF4F32DD2711800C3F20A /* PerfClock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerfClock.swift; sourceTree = "<group>"; };
63
65
  2B23CB3E2D0BEE6900E70D95 /* WindowContainerMgr.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowContainerMgr.swift; sourceTree = "<group>"; };
64
66
  2B2F1D632BEBFAAA006897EE /* WebSpatial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WebSpatial.app; sourceTree = BUILT_PRODUCTS_DIR; };
65
67
  2B2F1D672BEBFAAA006897EE /* RealityKitContent */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = RealityKitContent; sourceTree = "<group>"; };
@@ -123,6 +125,7 @@
123
125
  2B0B1C0E2C494E4100E644F9 /* Utils */ = {
124
126
  isa = PBXGroup;
125
127
  children = (
128
+ 2B0FF4F32DD2711800C3F20A /* PerfClock.swift */,
126
129
  2BD5880D2DB1236000C0E13B /* version.swift */,
127
130
  2BD510552D54A2FF0001E5E6 /* SceneManager.swift */,
128
131
  2B0B43092CBE21540003CEF3 /* CommandManager.swift */,
@@ -375,6 +378,7 @@
375
378
  2BE1E9032C9035DB00EAE76A /* SpatialInputComponent.swift in Sources */,
376
379
  2B2F1D9B2BEDA975006897EE /* PlainWindowContainerView.swift in Sources */,
377
380
  2BE1E8FA2C90332400EAE76A /* SpatialObject.swift in Sources */,
381
+ 2B0FF4F42DD2711E00C3F20A /* PerfClock.swift in Sources */,
378
382
  2BB28CCC2C747DB0007F4BDC /* OpenDismissHandlerUI.swift in Sources */,
379
383
  2BDBED632D3FE8EC0065443F /* SpatialModel3DView.swift in Sources */,
380
384
  2B67BBAC2D151C1A00BBC689 /* manifest.swift in Sources */,