node-mac-recorder 1.2.1 → 1.2.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.
Files changed (2) hide show
  1. package/README.md +97 -97
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -234,61 +234,47 @@ const thumbnail = await recorder.getDisplayThumbnail(0, {
234
234
 
235
235
  ### Cursor Tracking Methods
236
236
 
237
- #### `startCursorTracking(outputPath)`
237
+ #### `startCursorCapture(outputPath)`
238
238
 
239
- Starts tracking cursor movements and saves data to JSON file.
239
+ Starts automatic cursor tracking and saves data to JSON file in real-time.
240
240
 
241
241
  ```javascript
242
- await recorder.startCursorTracking("./cursor-data.json");
243
- // Cursor tracking started - will record position, cursor type, and events
242
+ await recorder.startCursorCapture("./cursor-data.json");
243
+ // Cursor tracking started - automatically writing to file
244
244
  ```
245
245
 
246
- #### `stopCursorTracking()`
246
+ #### `stopCursorCapture()`
247
247
 
248
- Stops cursor tracking and saves collected data.
248
+ Stops cursor tracking and closes the output file.
249
249
 
250
250
  ```javascript
251
- await recorder.stopCursorTracking();
252
- // Data saved to specified JSON file
251
+ await recorder.stopCursorCapture();
252
+ // Tracking stopped, file closed
253
253
  ```
254
254
 
255
- #### `getCursorPosition()`
255
+ **JSON Output Format:**
256
256
 
257
- Gets current cursor position and type.
258
-
259
- ```javascript
260
- const position = recorder.getCursorPosition();
261
- console.log(position);
262
- // {
263
- // x: 1234,
264
- // y: 567,
265
- // cursorType: "default" // "default", "pointer", "grabbing", "text"
266
- // }
267
- ```
268
-
269
- #### `getCursorTrackingStatus()`
270
-
271
- Returns cursor tracking status and data count.
272
-
273
- ```javascript
274
- const status = recorder.getCursorTrackingStatus();
275
- console.log(status);
276
- // {
277
- // isTracking: true,
278
- // dataCount: 1250,
279
- // hasEventTap: true,
280
- // hasRunLoopSource: true
281
- // }
257
+ ```json
258
+ [
259
+ {
260
+ "x": 851,
261
+ "y": 432,
262
+ "timestamp": 201,
263
+ "cursorType": "default",
264
+ "type": "move"
265
+ },
266
+ {
267
+ "x": 851,
268
+ "y": 432,
269
+ "timestamp": 220,
270
+ "cursorType": "pointer",
271
+ "type": "mousedown"
272
+ }
273
+ ]
282
274
  ```
283
275
 
284
- #### `saveCursorData(outputPath)`
285
-
286
- Manually saves current cursor data to file.
287
-
288
- ```javascript
289
- await recorder.saveCursorData("./cursor-backup.json");
290
- // Data saved to file
291
- ```
276
+ **Cursor Types:** `default`, `pointer`, `text`, `grab`, `grabbing`, `ew-resize`, `ns-resize`, `crosshair`
277
+ **Event Types:** `move`, `mousedown`, `mouseup`, `rightmousedown`, `rightmouseup`
292
278
 
293
279
  ## Usage Examples
294
280
 
@@ -466,56 +452,51 @@ async function createDisplaySelector() {
466
452
  ### Cursor Tracking Usage
467
453
 
468
454
  ```javascript
469
- const recorder = new MacRecorder();
455
+ const MacRecorder = require("node-mac-recorder");
470
456
 
471
457
  async function trackUserInteraction() {
472
- // Start cursor tracking
473
- await recorder.startCursorTracking("./user-interactions.json");
474
- console.log("Cursor tracking started...");
475
-
476
- // Monitor real-time cursor position
477
- const monitorInterval = setInterval(() => {
478
- const position = recorder.getCursorPosition();
479
- console.log(
480
- `Cursor: ${position.x}, ${position.y} (${position.cursorType})`
481
- );
458
+ const recorder = new MacRecorder();
482
459
 
483
- const status = recorder.getCursorTrackingStatus();
484
- console.log(`Tracking status: ${status.dataCount} positions recorded`);
485
- }, 100); // Check every 100ms
460
+ try {
461
+ // Start cursor tracking - automatically writes to file
462
+ await recorder.startCursorCapture("./user-interactions.json");
463
+ console.log("✅ Cursor tracking started...");
486
464
 
487
- // Track for 10 seconds
488
- setTimeout(async () => {
489
- clearInterval(monitorInterval);
465
+ // Track for 5 seconds
466
+ console.log("📱 Move mouse and click for 5 seconds...");
467
+ await new Promise((resolve) => setTimeout(resolve, 5000));
490
468
 
491
- // Stop tracking and save data
492
- await recorder.stopCursorTracking();
493
- console.log("Cursor tracking completed!");
469
+ // Stop tracking
470
+ await recorder.stopCursorCapture();
471
+ console.log("Cursor tracking completed!");
494
472
 
495
- // Load and analyze the data
473
+ // Analyze the data
496
474
  const fs = require("fs");
497
475
  const data = JSON.parse(
498
476
  fs.readFileSync("./user-interactions.json", "utf8")
499
477
  );
500
478
 
501
- console.log(`Total interactions recorded: ${data.length}`);
479
+ console.log(`📄 ${data.length} events recorded`);
480
+
481
+ // Count clicks
482
+ const clicks = data.filter((d) => d.type === "mousedown").length;
483
+ if (clicks > 0) {
484
+ console.log(`🖱️ ${clicks} clicks detected`);
485
+ }
502
486
 
503
- // Analyze cursor types
487
+ // Most used cursor type
504
488
  const cursorTypes = {};
505
489
  data.forEach((item) => {
506
490
  cursorTypes[item.cursorType] = (cursorTypes[item.cursorType] || 0) + 1;
507
491
  });
508
492
 
509
- console.log("Cursor types distribution:", cursorTypes);
510
-
511
- // Analyze event types
512
- const eventTypes = {};
513
- data.forEach((item) => {
514
- eventTypes[item.type] = (eventTypes[item.type] || 0) + 1;
515
- });
516
-
517
- console.log("Event types distribution:", eventTypes);
518
- }, 10000);
493
+ const mostUsed = Object.keys(cursorTypes).reduce((a, b) =>
494
+ cursorTypes[a] > cursorTypes[b] ? a : b
495
+ );
496
+ console.log(`🎯 Most used cursor: ${mostUsed}`);
497
+ } catch (error) {
498
+ console.error("❌ Error:", error.message);
499
+ }
519
500
  }
520
501
 
521
502
  trackUserInteraction();
@@ -524,33 +505,37 @@ trackUserInteraction();
524
505
  ### Combined Screen Recording + Cursor Tracking
525
506
 
526
507
  ```javascript
527
- const recorder = new MacRecorder();
508
+ const MacRecorder = require("node-mac-recorder");
528
509
 
529
510
  async function recordWithCursorTracking() {
530
- // Start both screen recording and cursor tracking
531
- await Promise.all([
532
- recorder.startRecording("./screen-recording.mov", {
533
- captureCursor: false, // Don't show cursor in video
534
- includeSystemAudio: true,
535
- quality: "high",
536
- }),
537
- recorder.startCursorTracking("./cursor-data.json"),
538
- ]);
539
-
540
- console.log("Recording screen and tracking cursor...");
541
-
542
- // Record for 30 seconds
543
- setTimeout(async () => {
511
+ const recorder = new MacRecorder();
512
+
513
+ try {
514
+ // Start both screen recording and cursor tracking
544
515
  await Promise.all([
545
- recorder.stopRecording(),
546
- recorder.stopCursorTracking(),
516
+ recorder.startRecording("./screen-recording.mov", {
517
+ captureCursor: false, // Don't show cursor in video
518
+ includeSystemAudio: true,
519
+ quality: "high",
520
+ }),
521
+ recorder.startCursorCapture("./cursor-data.json"),
547
522
  ]);
548
523
 
549
- console.log("Screen recording and cursor tracking completed!");
550
- console.log("Files created:");
551
- console.log("- screen-recording.mov");
552
- console.log("- cursor-data.json");
553
- }, 30000);
524
+ console.log(" Recording screen and tracking cursor...");
525
+
526
+ // Record for 10 seconds
527
+ await new Promise((resolve) => setTimeout(resolve, 10000));
528
+
529
+ // Stop both
530
+ await Promise.all([recorder.stopRecording(), recorder.stopCursorCapture()]);
531
+
532
+ console.log("✅ Recording completed!");
533
+ console.log("📁 Files created:");
534
+ console.log(" - screen-recording.mov");
535
+ console.log(" - cursor-data.json");
536
+ } catch (error) {
537
+ console.error("❌ Error:", error.message);
538
+ }
554
539
  }
555
540
 
556
541
  recordWithCursorTracking();
@@ -651,6 +636,21 @@ The `getWindows()` method automatically filters out:
651
636
  - **Memory Efficient** - Proper memory management in native layer
652
637
  - **Quality Presets** - Balanced quality/performance options
653
638
 
639
+ ## Testing
640
+
641
+ Run the included demo to test cursor tracking:
642
+
643
+ ```bash
644
+ node cursor-test.js
645
+ ```
646
+
647
+ This will:
648
+
649
+ - ✅ Start cursor tracking for 5 seconds
650
+ - 📱 Capture mouse movements and clicks
651
+ - 📄 Save data to `cursor-data.json`
652
+ - 🖱️ Report clicks detected
653
+
654
654
  ## Troubleshooting
655
655
 
656
656
  ### Permission Issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mac-recorder",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Native macOS screen recording package for Node.js applications",
5
5
  "main": "index.js",
6
6
  "keywords": [