node-mac-recorder 2.1.3 โ†’ 2.2.1

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.
@@ -0,0 +1,164 @@
1
+ const MacRecorder = require('./index');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ function runComprehensiveTests() {
6
+ console.log('๐Ÿงช Running Comprehensive ScreenCaptureKit Tests\n');
7
+ console.log('=' .repeat(60));
8
+
9
+ const recorder = new MacRecorder();
10
+ let testResults = {
11
+ passed: 0,
12
+ failed: 0,
13
+ details: []
14
+ };
15
+
16
+ function addResult(testName, passed, details = '') {
17
+ testResults.details.push({
18
+ name: testName,
19
+ passed,
20
+ details
21
+ });
22
+
23
+ if (passed) {
24
+ testResults.passed++;
25
+ console.log(`โœ… ${testName}`);
26
+ } else {
27
+ testResults.failed++;
28
+ console.log(`โŒ ${testName}: ${details}`);
29
+ }
30
+ if (details && passed) {
31
+ console.log(` ${details}`);
32
+ }
33
+ }
34
+
35
+ // Test 1: Module Loading
36
+ try {
37
+ addResult('Module Loading', true, 'MacRecorder class instantiated successfully');
38
+ } catch (error) {
39
+ addResult('Module Loading', false, error.message);
40
+ }
41
+
42
+ // Test 2: Method Availability
43
+ const expectedMethods = [
44
+ 'getDisplays', 'getWindows', 'getAudioDevices', 'startRecording',
45
+ 'stopRecording', 'checkPermissions', 'getCursorPosition',
46
+ 'getWindowThumbnail', 'getDisplayThumbnail'
47
+ ];
48
+
49
+ let missingMethods = [];
50
+ expectedMethods.forEach(method => {
51
+ if (typeof recorder[method] !== 'function') {
52
+ missingMethods.push(method);
53
+ }
54
+ });
55
+
56
+ if (missingMethods.length === 0) {
57
+ addResult('API Method Availability', true, `All ${expectedMethods.length} expected methods available`);
58
+ } else {
59
+ addResult('API Method Availability', false, `Missing methods: ${missingMethods.join(', ')}`);
60
+ }
61
+
62
+ // Test 3: Synchronous Operations
63
+ try {
64
+ const cursor = recorder.getCurrentCursorPosition();
65
+ if (cursor && typeof cursor.x === 'number' && typeof cursor.y === 'number') {
66
+ addResult('Cursor Position (Sync)', true, `Position: (${cursor.x}, ${cursor.y}), Type: ${cursor.cursorType}`);
67
+ } else {
68
+ addResult('Cursor Position (Sync)', false, 'Invalid cursor data returned');
69
+ }
70
+ } catch (error) {
71
+ addResult('Cursor Position (Sync)', false, error.message);
72
+ }
73
+
74
+ // Test 4: Cursor Capture Status
75
+ try {
76
+ const status = recorder.getCursorCaptureStatus();
77
+ addResult('Cursor Capture Status', true, `Tracking: ${status.isTracking || false}`);
78
+ } catch (error) {
79
+ addResult('Cursor Capture Status', false, error.message);
80
+ }
81
+
82
+ console.log('\n' + 'โ”€'.repeat(60));
83
+ console.log('๐Ÿ“Š Test Results Summary:');
84
+ console.log('โ”€'.repeat(60));
85
+ console.log(`โœ… Passed: ${testResults.passed}`);
86
+ console.log(`โŒ Failed: ${testResults.failed}`);
87
+ console.log(`๐Ÿ“ˆ Success Rate: ${Math.round((testResults.passed / (testResults.passed + testResults.failed)) * 100)}%`);
88
+
89
+ console.log('\n๐Ÿ” Detailed Analysis:');
90
+ console.log('โ”€'.repeat(60));
91
+
92
+ // Test async operations with timeout
93
+ console.log('\n๐Ÿ”„ Testing Async Operations (with 8s timeout each):');
94
+
95
+ let asyncTests = 0;
96
+ let asyncPassed = 0;
97
+
98
+ function testAsync(testName, asyncFunction, timeout = 8000) {
99
+ return new Promise((resolve) => {
100
+ asyncTests++;
101
+ const timeoutId = setTimeout(() => {
102
+ console.log(`โš ๏ธ ${testName}: Timed out after ${timeout/1000}s (likely permission dialog)`);
103
+ resolve(false);
104
+ }, timeout);
105
+
106
+ try {
107
+ asyncFunction((error, result) => {
108
+ clearTimeout(timeoutId);
109
+ if (error) {
110
+ console.log(`โŒ ${testName}: ${error.message || error}`);
111
+ resolve(false);
112
+ } else {
113
+ const resultInfo = Array.isArray(result) ? `${result.length} items` : 'Success';
114
+ console.log(`โœ… ${testName}: ${resultInfo}`);
115
+ asyncPassed++;
116
+ resolve(true);
117
+ }
118
+ });
119
+ } catch (error) {
120
+ clearTimeout(timeoutId);
121
+ console.log(`โŒ ${testName}: ${error.message}`);
122
+ resolve(false);
123
+ }
124
+ });
125
+ }
126
+
127
+ // Run async tests sequentially
128
+ (async () => {
129
+ await testAsync('Permissions Check', (cb) => recorder.checkPermissions(cb));
130
+ await testAsync('Display Enumeration', (cb) => recorder.getDisplays(cb));
131
+ await testAsync('Window Enumeration', (cb) => recorder.getWindows(cb));
132
+ await testAsync('Audio Device Enumeration', (cb) => recorder.getAudioDevices(cb));
133
+
134
+ console.log('\n' + 'โ•'.repeat(60));
135
+ console.log('๐Ÿ Final Test Summary:');
136
+ console.log('โ•'.repeat(60));
137
+ console.log(`๐Ÿ”ง Synchronous Tests: ${testResults.passed}/${testResults.passed + testResults.failed} passed`);
138
+ console.log(`๐Ÿ”„ Asynchronous Tests: ${asyncPassed}/${asyncTests} passed`);
139
+ console.log(`๐Ÿ“Š Overall: ${testResults.passed + asyncPassed}/${testResults.passed + testResults.failed + asyncTests} tests passed`);
140
+
141
+ const overallSuccess = Math.round(((testResults.passed + asyncPassed) / (testResults.passed + testResults.failed + asyncTests)) * 100);
142
+
143
+ if (overallSuccess >= 80) {
144
+ console.log(`\n๐ŸŽ‰ ScreenCaptureKit Migration: ${overallSuccess}% SUCCESS!`);
145
+ console.log('โœจ The migration is working correctly');
146
+ } else if (overallSuccess >= 60) {
147
+ console.log(`\nโš ๏ธ ScreenCaptureKit Migration: ${overallSuccess}% PARTIAL SUCCESS`);
148
+ console.log('๐Ÿ”ง Some functionality working, permissions may need attention');
149
+ } else {
150
+ console.log(`\nโŒ ScreenCaptureKit Migration: ${overallSuccess}% - NEEDS WORK`);
151
+ console.log('๐Ÿšจ Multiple issues detected');
152
+ }
153
+
154
+ console.log('\n๐Ÿ’ก Notes:');
155
+ console.log('โ€ข Timeouts usually indicate missing screen recording permissions');
156
+ console.log('โ€ข Enable permissions in: System Preferences > Privacy & Security > Screen Recording');
157
+ console.log('โ€ข ScreenCaptureKit requires macOS 12.3+ and arm64 architecture');
158
+ console.log('โ€ข All synchronous operations (cursor tracking) should work without permissions');
159
+
160
+ process.exit(0);
161
+ })();
162
+ }
163
+
164
+ runComprehensiveTests();
@@ -0,0 +1,142 @@
1
+ const MacRecorder = require("./index");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ async function testRecording() {
6
+ console.log("๐ŸŽฌ Testing ScreenCaptureKit Recording...\n");
7
+
8
+ const recorder = new MacRecorder();
9
+ const outputDir = path.join(__dirname, "test-output");
10
+
11
+ // Create test output directory
12
+ if (!fs.existsSync(outputDir)) {
13
+ fs.mkdirSync(outputDir);
14
+ console.log("๐Ÿ“ Created test-output directory");
15
+ }
16
+
17
+ const outputFile = path.resolve(outputDir, "sck-test-recording.mov");
18
+ console.log(`๐Ÿ“น Output file: ${outputFile}`);
19
+
20
+ // Test recording options
21
+ const recordingOptions = {
22
+ captureCursor: true,
23
+ excludeCurrentApp: true,
24
+ includeMicrophone: true,
25
+ includeSystemAudio: true, // Disable to avoid permission issues for now
26
+ displayId: null, // Will use main display
27
+ };
28
+
29
+ console.log(
30
+ "๐Ÿ“ Recording options:",
31
+ JSON.stringify(recordingOptions, null, 2)
32
+ );
33
+ console.log("\n๐Ÿš€ Starting recording test...");
34
+
35
+ try {
36
+ // Test current cursor position before recording
37
+ const cursor = recorder.getCurrentCursorPosition();
38
+ console.log(
39
+ `๐Ÿ–ฑ๏ธ Current cursor: x=${cursor.x}, y=${cursor.y}, type=${cursor.cursorType}`
40
+ );
41
+
42
+ // Determine a window to exclude (prefer a window with name containing "Cursor")
43
+ try {
44
+ const windows = await recorder.getWindows();
45
+ if (Array.isArray(windows) && windows.length) {
46
+ const pick =
47
+ windows.find(
48
+ (w) =>
49
+ (typeof w.appName === "string" && /cursor/i.test(w.appName)) ||
50
+ (typeof w.name === "string" && /cursor/i.test(w.name)) ||
51
+ (typeof w.title === "string" && /cursor/i.test(w.title))
52
+ ) || windows[0];
53
+ const wid = pick?.id ?? pick?.windowId ?? pick?.windowID ?? null;
54
+ if (wid != null) {
55
+ recordingOptions.excludeWindowIds = [Number(wid)];
56
+ }
57
+ }
58
+ } catch (_) {}
59
+
60
+ // Start recording
61
+ console.log("โ–ถ๏ธ Attempting to start recording...");
62
+
63
+ // Start recording without callback first
64
+ console.log("๐Ÿ” Attempting startRecording without callback...");
65
+
66
+ let startResult;
67
+ try {
68
+ startResult = await recorder.startRecording(outputFile, recordingOptions);
69
+ console.log(`๐Ÿ“Š startRecording resolved: ${startResult}`);
70
+ } catch (error) {
71
+ console.error("โŒ startRecording threw error:", error.message);
72
+ console.error("Stack:", error.stack);
73
+ return;
74
+ }
75
+
76
+ if (startResult) {
77
+ console.log("โœ… Recording started successfully");
78
+ console.log("โฑ๏ธ Recording for 3 seconds...");
79
+
80
+ // Record for ~6 seconds
81
+ setTimeout(async () => {
82
+ console.log("โน๏ธ Stopping recording...");
83
+
84
+ let stopResult;
85
+ try {
86
+ stopResult = await recorder.stopRecording();
87
+ console.log(
88
+ `๐Ÿ“Š stopRecording resolved: ${JSON.stringify(stopResult)}`
89
+ );
90
+
91
+ if (stopResult && stopResult.code === 0) {
92
+ console.log("โœ… Stop recording command sent");
93
+ } else {
94
+ console.log("โŒ Failed to send stop recording command");
95
+ }
96
+ } catch (error) {
97
+ console.error("โŒ stopRecording threw error:", error.message);
98
+ console.error("Stack:", error.stack);
99
+ }
100
+
101
+ // Final check after a longer delay
102
+ setTimeout(() => {
103
+ console.log("\n๐Ÿ“Š Final Results:");
104
+
105
+ try {
106
+ if (fs.existsSync(outputFile)) {
107
+ const stats = fs.statSync(outputFile);
108
+ console.log(`โœ… Recording file exists: ${stats.size} bytes`);
109
+ console.log(`๐Ÿ“ Location: ${outputFile}`);
110
+ console.log("๐ŸŽฏ ScreenCaptureKit recording test PASSED");
111
+ } else {
112
+ console.log("โŒ Recording file does not exist");
113
+ console.log(
114
+ "๐Ÿ” This might be due to permissions or ScreenCaptureKit configuration"
115
+ );
116
+ }
117
+ } catch (error) {
118
+ console.error("โŒ Final check error:", error.message);
119
+ }
120
+
121
+ console.log("\nโœ… Recording test completed");
122
+ }, 4000);
123
+ }, 6000);
124
+ } else {
125
+ console.log("โŒ Failed to start recording");
126
+ console.log("๐Ÿ” Possible causes:");
127
+ console.log(" โ€ข Screen recording permissions not granted");
128
+ console.log(" โ€ข ScreenCaptureKit not available (requires macOS 12.3+)");
129
+ console.log(" โ€ข Display/window selection issues");
130
+ }
131
+ } catch (error) {
132
+ console.error("โŒ Recording test failed with exception:", error);
133
+ }
134
+ }
135
+
136
+ // Handle process exit
137
+ process.on("SIGINT", () => {
138
+ console.log("\nโš ๏ธ Recording test interrupted");
139
+ process.exit(0);
140
+ });
141
+
142
+ testRecording();
@@ -0,0 +1,37 @@
1
+ const MacRecorder = require('./index');
2
+
3
+ async function testScreenCaptureKit() {
4
+ console.log('Testing ScreenCaptureKit migration...');
5
+
6
+ const recorder = new MacRecorder();
7
+
8
+ try {
9
+ // Test 1: Check permissions
10
+ console.log('\n1. Testing checkPermissions()');
11
+ const permissions = await recorder.checkPermissions();
12
+ console.log('โœ… Permissions:', permissions);
13
+
14
+ // Test 2: Get displays
15
+ console.log('\n2. Testing getDisplays()');
16
+ const displays = await recorder.getDisplays();
17
+ console.log(`โœ… Found ${displays.length} displays:`, displays.map(d => `${d.id}:${d.width}x${d.height}`));
18
+
19
+ // Test 3: Get windows
20
+ console.log('\n3. Testing getWindows()');
21
+ const windows = await recorder.getWindows();
22
+ console.log(`โœ… Found ${windows.length} windows:`, windows.slice(0, 3).map(w => `${w.id}:"${w.title}"`));
23
+
24
+ // Test 4: Get audio devices
25
+ console.log('\n4. Testing getAudioDevices()');
26
+ const audioDevices = await recorder.getAudioDevices();
27
+ console.log(`โœ… Found ${audioDevices.length} audio devices:`, audioDevices.slice(0, 3).map(d => `${d.id}:"${d.name}"`));
28
+
29
+ console.log('\n๐ŸŽ‰ All ScreenCaptureKit tests passed!');
30
+ console.log('\nโœ… ScreenCaptureKit migration successful!');
31
+
32
+ } catch (error) {
33
+ console.error('โŒ Test failed:', error);
34
+ }
35
+ }
36
+
37
+ testScreenCaptureKit();
package/test-sck.js CHANGED
@@ -1,3 +1,4 @@
1
+ <<<<<<< HEAD
1
2
  const nativeBinding = require('./build/Release/mac_recorder.node');
2
3
 
3
4
  console.log('=== ScreenCaptureKit Migration Test ===');
@@ -47,4 +48,62 @@ try {
47
48
  }
48
49
  } catch (error) {
49
50
  console.error('Recording test failed:', error.message);
50
- }
51
+ }
52
+ =======
53
+ const MacRecorder = require('./index');
54
+
55
+ function testScreenCaptureKit() {
56
+ console.log('Testing ScreenCaptureKit migration...');
57
+
58
+ const recorder = new MacRecorder();
59
+
60
+ try {
61
+ // Test getting displays
62
+ console.log('\n1. Testing getDisplays()');
63
+ recorder.getDisplays((err, displays) => {
64
+ if (err) {
65
+ console.error('getDisplays failed:', err);
66
+ return;
67
+ }
68
+ console.log(`Found ${displays.length} displays:`, displays);
69
+
70
+ // Test getting windows
71
+ console.log('\n2. Testing getWindows()');
72
+ recorder.getWindows((err, windows) => {
73
+ if (err) {
74
+ console.error('getWindows failed:', err);
75
+ return;
76
+ }
77
+ console.log(`Found ${windows.length} windows:`, windows.slice(0, 3));
78
+
79
+ // Test getting audio devices
80
+ console.log('\n3. Testing getAudioDevices()');
81
+ recorder.getAudioDevices((err, audioDevices) => {
82
+ if (err) {
83
+ console.error('getAudioDevices failed:', err);
84
+ return;
85
+ }
86
+ console.log(`Found ${audioDevices.length} audio devices:`, audioDevices.slice(0, 3));
87
+
88
+ // Test permissions
89
+ console.log('\n4. Testing checkPermissions()');
90
+ recorder.checkPermissions((err, hasPermissions) => {
91
+ if (err) {
92
+ console.error('checkPermissions failed:', err);
93
+ return;
94
+ }
95
+ console.log(`Has permissions: ${hasPermissions}`);
96
+
97
+ console.log('\nโœ… All basic tests passed! ScreenCaptureKit migration successful.');
98
+ });
99
+ });
100
+ });
101
+ });
102
+
103
+ } catch (error) {
104
+ console.error('โŒ Test failed:', error);
105
+ }
106
+ }
107
+
108
+ testScreenCaptureKit();
109
+ >>>>>>> screencapture
package/test-sync.js ADDED
@@ -0,0 +1,52 @@
1
+ const MacRecorder = require('./index');
2
+
3
+ console.log('๐Ÿ”„ Testing ScreenCaptureKit Synchronous Operations...\n');
4
+
5
+ try {
6
+ const recorder = new MacRecorder();
7
+ console.log('โœ… Recorder created successfully');
8
+
9
+ // Test if we can access the native module methods directly
10
+ console.log('๐Ÿ“‹ Available methods:');
11
+ const methods = Object.getOwnPropertyNames(recorder.__proto__);
12
+ methods.forEach(method => {
13
+ if (typeof recorder[method] === 'function') {
14
+ console.log(` โ€ข ${method}()`);
15
+ }
16
+ });
17
+
18
+ console.log('\n๐ŸŽฏ Testing basic functionality:');
19
+
20
+ // Test recording status (should be sync and work)
21
+ try {
22
+ const status = recorder.getStatus();
23
+ console.log(`โœ… getStatus(): ${JSON.stringify(status)}`);
24
+ } catch (err) {
25
+ console.log(`โŒ getStatus() failed: ${err.message}`);
26
+ }
27
+
28
+ // Test cursor position (should be sync and work)
29
+ try {
30
+ const cursor = recorder.getCurrentCursorPosition();
31
+ console.log(`โœ… getCurrentCursorPosition(): x=${cursor.x}, y=${cursor.y}, type=${cursor.cursorType}`);
32
+ } catch (err) {
33
+ console.log(`โŒ getCurrentCursorPosition() failed: ${err.message}`);
34
+ }
35
+
36
+ // Test cursor capture status (should be sync)
37
+ try {
38
+ const cursorStatus = recorder.getCursorCaptureStatus();
39
+ console.log(`โœ… getCursorCaptureStatus(): tracking=${cursorStatus.isTracking}`);
40
+ } catch (err) {
41
+ console.log(`โŒ getCursorCaptureStatus() failed: ${err.message}`);
42
+ }
43
+
44
+ console.log('\n๐Ÿ“Š ScreenCaptureKit sync tests completed');
45
+ console.log('โš ๏ธ Async functions (getDisplays, getWindows, getAudioDevices) may hang due to permission dialogs');
46
+ console.log('๐Ÿ’ก To fix: Grant screen recording permissions in System Preferences > Privacy & Security');
47
+
48
+ } catch (error) {
49
+ console.error('โŒ Critical error:', error);
50
+ }
51
+
52
+ process.exit(0);
@@ -0,0 +1,57 @@
1
+ const MacRecorder = require('./index');
2
+
3
+ function testWindowSelection() {
4
+ console.log('๐Ÿ” Testing ScreenCaptureKit Window Selection...\n');
5
+
6
+ const recorder = new MacRecorder();
7
+
8
+ try {
9
+ // Test window enumeration
10
+ recorder.getWindows((err, windows) => {
11
+ if (err) {
12
+ console.error('โŒ getWindows failed:', err);
13
+ return;
14
+ }
15
+
16
+ console.log(`โœ… Found ${windows.length} windows`);
17
+
18
+ // Show first few windows with details
19
+ windows.slice(0, 5).forEach((window, index) => {
20
+ console.log(`${index + 1}. "${window.name}" - ${window.appName}`);
21
+ console.log(` ID: ${window.id}, Size: ${window.width}x${window.height}, Position: (${window.x}, ${window.y})`);
22
+ console.log(` On Screen: ${window.isOnScreen !== false ? 'Yes' : 'No'}\n`);
23
+ });
24
+
25
+ // Test window thumbnails if we have windows
26
+ if (windows.length > 0) {
27
+ const firstWindow = windows[0];
28
+ console.log(`๐Ÿ“ธ Testing window thumbnail for: "${firstWindow.name}"`);
29
+
30
+ recorder.getWindowThumbnail(firstWindow.id, 300, 200, (err, thumbnail) => {
31
+ if (err) {
32
+ console.error('โŒ getWindowThumbnail failed:', err);
33
+ } else {
34
+ console.log(`โœ… Window thumbnail generated: ${thumbnail.length} characters (base64)`);
35
+
36
+ // Test window recording info
37
+ console.log(`\n๐ŸŽฌ Window recording info:`);
38
+ console.log(` Target Window: "${firstWindow.name}" (ID: ${firstWindow.id})`);
39
+ console.log(` App: ${firstWindow.appName}`);
40
+ console.log(` Capture Area: ${firstWindow.width}x${firstWindow.height}`);
41
+ console.log(` Would use windowId option for recording`);
42
+
43
+ console.log('\nโœ… Window selection tests completed successfully!');
44
+ }
45
+ });
46
+ } else {
47
+ console.log('โš ๏ธ No windows found for thumbnail testing');
48
+ console.log('\nโœ… Window enumeration test completed successfully!');
49
+ }
50
+ });
51
+
52
+ } catch (error) {
53
+ console.error('โŒ Window selection test failed:', error);
54
+ }
55
+ }
56
+
57
+ testWindowSelection();