@mediaway/device 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +83 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @mediaway/device
2
+
3
+ Camera, microphone, and screen capture over Mediaway's C ABI
4
+ (`mediaway_ffi.dll`). Capture is **poll-based and synchronous** — frames are
5
+ ready when `pollFrame()` returns one; it never blocks waiting for hardware.
6
+
7
+ Windows is the verified platform (Media Foundation backends). Linux camera
8
+ backends compile; other platforms are not implemented yet.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @mediaway/device
14
+ ```
15
+
16
+ ## Camera example
17
+
18
+ ```ts
19
+ import { openCamera, CaptureUnavailableError, type VideoFrame } from "@mediaway/device";
20
+
21
+ const camera = await openCamera({ index: 0, timeBase: { num: 1, den: 30 } });
22
+ console.log(`camera: ${camera.width}x${camera.height}`);
23
+
24
+ const frames: Buffer[] = [];
25
+ const started = Date.now();
26
+ while (Date.now() - started < 3_000) {
27
+ const frame = camera.pollFrame(); // VideoFrame | null — never blocks
28
+ if (frame) frames.push(Buffer.from(frame.data)); // NV12 planes
29
+ }
30
+ await camera.close(); // joins the backend worker thread (up to one frame interval)
31
+ ```
32
+
33
+ Handle a missing camera cleanly:
34
+
35
+ ```ts
36
+ try {
37
+ const camera = await openCamera({ index: 0, timeBase: { num: 1, den: 30 } });
38
+ // ... record
39
+ } catch (err) {
40
+ if (err instanceof CaptureUnavailableError) console.log("no camera here");
41
+ else throw err;
42
+ }
43
+ ```
44
+
45
+ ## Microphone
46
+
47
+ ```ts
48
+ import { openMicrophone } from "@mediaway/device";
49
+
50
+ const mic = await openMicrophone({ sampleRate: 48_000, channels: 1 });
51
+ // mic.sampleRate, mic.channels
52
+ const frame = mic.pollFrame(); // AudioFrame | null — raw interleaved f32le PCM
53
+ await mic.close();
54
+ ```
55
+
56
+ ## Screen capture
57
+
58
+ ```ts
59
+ import { openScreenCapture } from "@mediaway/device";
60
+
61
+ const screen = await openScreenCapture({
62
+ timeBase: { num: 1, den: 30 },
63
+ captureCursor: true,
64
+ });
65
+ const frame = screen.pollFrame(); // VideoFrame | null
66
+ await screen.close();
67
+ ```
68
+
69
+ ## API
70
+
71
+ | Function | Session | Frames |
72
+ | --- | --- | --- |
73
+ | `openCamera({ index, timeBase })` | `CameraSession` (`width`, `height`, `pixelFormat` = `"nv12"`) | `pollFrame(): VideoFrame \| null` |
74
+ | `openMicrophone({ sampleRate, channels })` | `MicSession` (`sampleRate`, `channels`) | `pollFrame(): AudioFrame \| null` |
75
+ | `openScreenCapture({ timeBase, captureCursor? })` | `ScreenSession` | `pollFrame(): VideoFrame \| null` |
76
+
77
+ Every session's `close()` is async (joins the backend worker thread).
78
+ `CaptureUnavailableError` signals a missing device.
79
+
80
+ ## License
81
+
82
+ MIT OR Apache-2.0. Part of the [Mediaway](https://github.com/nyxways/mediaway)
83
+ project — pre-1.0, APIs may change.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mediaway/device",
3
- "version": "0.1.0",
4
- "description": "Mediaway camera/mic/screen capture over the C ABI (mediaway-ffi)",
3
+ "version": "0.1.1",
4
+ "description": "Camera, microphone, and screen capture for Node.js (poll-based, never blocks)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",