@touchcastllc/napster-companion-api 1.0.0-alpha.34 → 1.0.0-alpha.35

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 (2) hide show
  1. package/README.md +115 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -523,7 +523,90 @@ const instance = await NapsterCompanionApiSdk.init(token, {
523
523
  });
524
524
  ```
525
525
 
526
- ### 3.2 Position & Layout
526
+ ### 3.2 Face Tracking
527
+
528
+ Real-time face detection using TensorFlow.js + MediaPipe Face Mesh. Detects the user's face via their camera, extracts 468 facial landmarks, and determines talking state via mouth-opening ratio. Fully client-side — no backend involved.
529
+
530
+ #### Prerequisites
531
+
532
+ Install the optional peer dependencies (only needed when face tracking is enabled):
533
+
534
+ ```bash
535
+ npm install @tensorflow/tfjs @tensorflow-models/face-landmarks-detection
536
+ ```
537
+
538
+ These libraries (~2MB) are lazy-loaded at runtime — they are not included in the main SDK bundle.
539
+
540
+ #### Enable & Configure
541
+
542
+ ```typescript
543
+ const instance = await NapsterCompanionApiSdk.init(token, {
544
+ features: {
545
+ faceTracking: {
546
+ enabled: true,
547
+ fps: 15, // Detection rate: 1–30 FPS (default: 15)
548
+ talkingThreshold: 0.015, // Mouth opening ratio threshold (default: 0.015)
549
+ },
550
+ },
551
+ onFaceTrackingData: (data) => {
552
+ if (data) {
553
+ console.log("Talking:", data.isTalking);
554
+ console.log("Landmarks:", data.landmarks.length); // 468
555
+ console.log("Mouth:", data.mouthLandmarks);
556
+ } else {
557
+ console.log("No face detected");
558
+ }
559
+ },
560
+ onFaceTrackingError: (error) => {
561
+ console.error("Face tracking error:", error.message);
562
+ },
563
+ });
564
+ ```
565
+
566
+ #### Start & Stop
567
+
568
+ ```typescript
569
+ // Start detection (opens camera, loads model on first call)
570
+ await instance.startFaceTracking();
571
+
572
+ // Pause detection (stops camera, keeps model loaded for fast restart)
573
+ instance.stopFaceTracking();
574
+
575
+ // Restart — reuses model, only reopens camera
576
+ await instance.startFaceTracking();
577
+ ```
578
+
579
+ #### Face Tracking Data
580
+
581
+ Each detection frame emits a `FaceTrackingData` object (or `null` if no face is detected):
582
+
583
+ ```typescript
584
+ interface FaceTrackingData {
585
+ landmarks: Array<{ x: number; y: number; z: number }>; // 468 points, 0–1 normalized
586
+ mouthLandmarks: {
587
+ topLip: { x: number; y: number };
588
+ bottomLip: { x: number; y: number };
589
+ leftCorner: { x: number; y: number };
590
+ rightCorner: { x: number; y: number };
591
+ } | null;
592
+ isTalking: boolean; // smoothed mouth-opening ratio > threshold
593
+ }
594
+ ```
595
+
596
+ #### Error Codes
597
+
598
+ | Code | When |
599
+ | -------------------------- | ----------------------------------------- |
600
+ | `CAMERA_PERMISSION_DENIED` | User denied camera access |
601
+ | `CAMERA_NOT_FOUND` | No camera available |
602
+ | `MODEL_LOAD_FAILED` | TensorFlow.js / MediaPipe failed to load |
603
+ | `DETECTION_FAILED` | Runtime detection error |
604
+
605
+ #### Cleanup
606
+
607
+ Face tracking is automatically destroyed when `instance.destroy()` is called. The model is disposed and camera tracks are stopped.
608
+
609
+ ### 3.3 Position & Layout
527
610
 
528
611
  Customize the avatar's position on the screen using predefined positions or custom styles. Also you can override the position using style properties.
529
612
 
@@ -685,7 +768,27 @@ if (instance.isFeatureEnabled("disclaimer")) {
685
768
  }
686
769
  ```
687
770
 
688
- ### 5.4 Communication Methods
771
+ ### 5.4 Face Tracking Methods
772
+
773
+ #### `startFaceTracking(): Promise<void>`
774
+
775
+ Start face tracking. Opens the user's camera and begins the detection loop. The model is loaded on the first call and reused on subsequent calls.
776
+
777
+ ```typescript
778
+ await instance.startFaceTracking();
779
+ ```
780
+
781
+ > **Note:** Requires `features.faceTracking.enabled = true` in the init config. Throws a `FeatureError` if not enabled.
782
+
783
+ #### `stopFaceTracking(): void`
784
+
785
+ Pause face tracking. Stops the camera and detection loop but keeps the model loaded for fast restart.
786
+
787
+ ```typescript
788
+ instance.stopFaceTracking();
789
+ ```
790
+
791
+ ### 5.5 Communication Methods
689
792
 
690
793
  #### `sendCommand(command: { type: string; data?: object }): void`
691
794
 
@@ -736,6 +839,11 @@ interface NapsterCompanionApiConfig {
736
839
  };
737
840
  disclaimer?: { enabled: boolean; text?: string };
738
841
  showSDKLoader?: { enabled: boolean; bgColor?: string };
842
+ faceTracking?: {
843
+ enabled: boolean;
844
+ fps?: number; // 1–30, default 15
845
+ talkingThreshold?: number; // default 0.015
846
+ };
739
847
  };
740
848
 
741
849
  // Configuration
@@ -749,6 +857,8 @@ interface NapsterCompanionApiConfig {
749
857
  onInactivityStatusChange?: (isInactive: boolean) => void;
750
858
  onDestroy?: () => void;
751
859
  onFeaturesUpdate?: (features: FeatureConfig) => void;
860
+ onFaceTrackingData?: (data: FaceTrackingData | null) => void;
861
+ onFaceTrackingError?: (error: Error) => void;
752
862
  }
753
863
  ```
754
864
 
@@ -767,6 +877,9 @@ npm install @touchcastllc/napster-companion-api
767
877
 
768
878
  # Install peer dependencies
769
879
  npm install @reduxjs/toolkit
880
+
881
+ # If using face tracking, also install:
882
+ npm install @tensorflow/tfjs @tensorflow-models/face-landmarks-detection
770
883
  ```
771
884
 
772
885
  **Problem: Invalid or expired token**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@touchcastllc/napster-companion-api",
3
- "version": "1.0.0-alpha.34",
3
+ "version": "1.0.0-alpha.35",
4
4
  "keywords": [
5
5
  "napster",
6
6
  "companion-api",