@viji-dev/core 0.8.17 → 0.9.0

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/README.md CHANGED
@@ -131,13 +131,17 @@ interface VijiCoreConfig {
131
131
  // Performance configuration
132
132
  frameRateMode?: 'full' | 'half' | 'quarter' | 'eighth'; // refresh rate / 1,2,4,8
133
133
 
134
- // Input streams
134
+ // Input streams (mutually exclusive with mediaSource)
135
135
  audioStream?: MediaStream; // Audio input for analysis
136
136
  videoStream?: MediaStream; // Video input (main, CV enabled)
137
137
  videoStreams?: MediaStream[]; // Additional video streams (no CV)
138
-
138
+
139
+ // Engine sharing: attach to another core's media analysis engines.
140
+ // One analysis pipeline serves all attached cores; analysis state
141
+ // (BPM lock, onset patterns) survives core transitions.
142
+ mediaSource?: VijiCore;
143
+
139
144
  // Feature toggles
140
- noInputs?: boolean; // Disable all input processing
141
145
  allowUserInteraction?: boolean; // Enable mouse/keyboard/touch events
142
146
  allowDeviceInteraction?: boolean; // Enable device sensors (motion/orientation/geolocation)
143
147
  }
@@ -1272,50 +1276,52 @@ The core provides extensive performance optimization capabilities:
1272
1276
  - **Efficient Communication**: Optimized message passing between components
1273
1277
  - **Memory Management**: Automatic resource cleanup and memory leak prevention
1274
1278
 
1275
- ### Multi-Instance Support
1279
+ ### Multi-Instance Support & Shared Media Engines
1276
1280
 
1277
- The core supports multiple concurrent instances for complex applications:
1281
+ The core supports multiple concurrent instances. Instances that should share
1282
+ analysis attach to a sibling's media engines via `mediaSource` — one audio
1283
+ pipeline / one AudioContext / one beat stack serves all attached cores, and
1284
+ the engines survive until the LAST attached core is destroyed:
1278
1285
 
1279
1286
  ```typescript
1280
- // Main scene with full features
1287
+ // Main scene owns the engines
1281
1288
  const mainCore = new VijiCore({
1282
1289
  hostContainer: document.getElementById('main-scene'),
1283
1290
  resolution: { width: 1920, height: 1080 },
1284
1291
  frameRateMode: 'full',
1285
1292
  allowUserInteraction: true,
1286
- audioStream: sharedAudioStream,
1287
- videoStream: sharedVideoStream
1293
+ audioStream,
1294
+ videoStream
1288
1295
  });
1289
1296
 
1290
- // Preview instance with reduced features
1291
- const previewCore = new VijiCore({
1292
- hostContainer: document.getElementById('preview'),
1293
- resolution: 0.25, // 25% resolution for performance
1294
- frameRateMode: 'half',
1295
- noInputs: true,
1296
- allowUserInteraction: false,
1297
- audioStream: sharedAudioStream // Shared efficiently across instances
1297
+ // Second view shares mainCore's engines: zero extra analysis cost,
1298
+ // identical audio/beat data in both scenes
1299
+ const secondCore = new VijiCore({
1300
+ hostContainer: document.getElementById('second-view'),
1301
+ sceneCode: otherSceneCode,
1302
+ mediaSource: mainCore
1298
1303
  });
1299
1304
 
1300
- // Thumbnail instance for gallery view
1305
+ // Thumbnail instance for gallery view (no streams, no mediaSource:
1306
+ // no analysis engines are constructed at all — lazy creation)
1301
1307
  const thumbnailCore = new VijiCore({
1302
1308
  hostContainer: document.getElementById('thumbnail'),
1303
1309
  resolution: 0.1, // 10% resolution
1304
1310
  frameRateMode: 'half',
1305
- noInputs: true,
1306
1311
  allowUserInteraction: false
1307
1312
  });
1308
1313
 
1309
- // To change scenes, create a new instance and destroy the old one
1314
+ // Scene transitions: construct the successor REFERENCING the old core,
1315
+ // then destroy the old one. The engine reference is taken synchronously
1316
+ // in the constructor, so analysis state (BPM lock, onset patterns)
1317
+ // carries across with zero gap — no export/import step.
1310
1318
  const newCore = new VijiCore({
1311
1319
  hostContainer: document.getElementById('scene-host'),
1312
1320
  sceneCode: newSceneCode,
1313
- audioStream: sharedAudioStream,
1314
- videoStream: sharedVideoStream
1321
+ mediaSource: oldCore
1315
1322
  });
1316
-
1317
- // Automatic comprehensive cleanup when destroyed
1318
- await oldCore.destroy();
1323
+ await newCore.initialize();
1324
+ await oldCore.destroy(); // engines survive — newCore still references them
1319
1325
  ```
1320
1326
 
1321
1327
  ## 🔍 Error Handling