@remedia/node 0.0.0-stage → 0.1.0-dev.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Twilight
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,145 @@
1
- # Temporary Holding Version
1
+ # @remedia/node
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This directory contains the Rust N-API crate and public npm package for Remedia's embedded Node.js
4
+ bindings. The addon calls `remedia-core`, `remedia-discord`, and `remedia-observability` directly in
5
+ the Node process; it does not use `remedia-server` as an intermediary.
6
+
7
+ The TypeScript entrypoint exports `Remedia`, `PlaybackSession`, and `DiscordSession`. Playback
8
+ accepts local files, HTTP(S) URLs, in-memory `Buffer`/`Uint8Array` media, and binary Node.js
9
+ `Readable` streams. Standalone playback currently decodes into a null output; Discord sessions
10
+ encode PCM to Opus in `remedia-core` and send packets through the existing voice transport. The
11
+ application supplies its Discord Gateway send function and forwards raw Gateway packets to
12
+ `Remedia.receive()`; the TypeScript adapter handles OP 4 and collects matching voice dispatches
13
+ before opening the native transport. Session tokens and endpoints remain internal details.
14
+
15
+ Each `Remedia` owns an isolated observability context. Rust diagnostics are forwarded through a
16
+ bounded callback queue with `on('debug', listener)`; use `close()` to stop sessions, disconnect
17
+ transports, and shut down owned telemetry. Operational errors reject API Promises and remain
18
+ available on session state independently of diagnostic delivery.
19
+
20
+ Playback and voice sessions are typed Node `EventEmitter`s. Subscribe with exported
21
+ `PlaybackSessionEvents` and `VoiceSessionEvents` constants; `Remedia` forwards session lifecycle
22
+ events and provides `RemediaEvents`. `playbackStarted` means native processing began, while
23
+ `playbackCompleted` means natural EOF was processed, not that Discord buffers drained. Events are
24
+ generation-correlated. `play(source, { customMetadata })` keeps arbitrary application metadata in
25
+ JavaScript and includes it in that generation's lifecycle events. Ordered `hooks.beforePlay()`
26
+ middleware can cancel or reject a start before native playback. See the
27
+ [Node.js binding guide](https://github.com/twlite/remedia/blob/main/apps/docs/content/docs/node/bindings.mdx) for payloads and semantics.
28
+
29
+ ## Installation
30
+
31
+ Requires Node.js **22.18.0 or newer** (ESM).
32
+
33
+ ```sh
34
+ npm install @remedia/node
35
+ ```
36
+
37
+ Install FFmpeg 7 shared libraries separately before importing the package. npm does not install
38
+ FFmpeg or compile the addon. Required ABI majors are avcodec 61, avformat 61, avutil 59,
39
+ avfilter 10, and swresample 5. libopus is statically included; FFmpeg is dynamically linked.
40
+
41
+ Native runtime CI covers Linux x64/ARM64 glibc, macOS x64/ARM64, Windows x64 MSVC, and
42
+ FreeBSD x64. Additional build-only packages cover Linux x64/ARM64 musl, Linux ARMv7 hard-float GNU,
43
+ Windows x86/ARM64 MSVC, and Android ARM64/ARMv7 (API 24). Build-only targets have no native runtime
44
+ integration coverage. See the [distribution guide](https://github.com/twlite/remedia/blob/main/apps/docs/content/docs/node/distribution.mdx)
45
+ for verification limits and library discovery: `LD_LIBRARY_PATH` on Linux/FreeBSD,
46
+ `DYLD_LIBRARY_PATH` on macOS, and DLL directories on `PATH` on Windows. For load errors, check
47
+ matching architecture/ABI, transitive FFmpeg dependencies, and that optional npm dependencies were
48
+ installed. Windows also needs the Visual C++ v14 runtime.
49
+
50
+ ```js
51
+ import { Remedia } from '@remedia/node';
52
+
53
+ const remedia = await Remedia.create();
54
+ try {
55
+ const playback = remedia.createPlaybackSession();
56
+ await playback.play({ file: './audio.wav' });
57
+ console.log(await playback.wait());
58
+ } finally {
59
+ await remedia.close();
60
+ }
61
+ ```
62
+
63
+ This standalone session decodes into a null output; it does not play through local speakers.
64
+
65
+ ## Development
66
+
67
+ Install dependencies from the repository root, then run:
68
+
69
+ ```sh
70
+ pnpm --filter @remedia/node test
71
+ pnpm --filter @remedia/node build
72
+ ```
73
+
74
+ The test command builds the debug addon and runs local Node.js integration tests. `build` creates a
75
+ release addon and TypeScript declarations. N-API loader/declaration files are generated from the
76
+ Rust source by `@napi-rs/cli`; Vitest tests live in `tests/` and are grouped by behavior. Rust code
77
+ belongs in `src/`, TypeScript library code in `lib/`, and `dist/` is generated output. See the
78
+ [Node.js bindings topic](https://github.com/twlite/remedia/blob/main/apps/docs/content/docs/node/bindings.mdx) for the API and current
79
+ limitations.
80
+
81
+ ## License and media responsibility
82
+
83
+ Remedia is a general-purpose media processing and transport engine. It does not provide media
84
+ content or grant rights to access or use third-party media. Developers and operators are responsible
85
+ for ensuring their use complies with applicable laws, intellectual property rights, and third-party
86
+ service terms.
87
+
88
+ Remedia is provided under the [MIT License](./LICENSE) without warranty. Dependency terms remain
89
+ separate; see [third-party notices](./THIRD_PARTY_NOTICES.md), including bundled libopus and
90
+ independently installed FFmpeg.
91
+
92
+ ## Session configuration and channel movement
93
+
94
+ A client owns one session per guild. Separate clients (including separate bot users) can use the
95
+ same guild and channel with independent playback, transport generations, and events. `userId` is
96
+ the Discord bot user ID, not a Remedia client session ID. Channel IDs are mutable destinations.
97
+ Duplicate guild registration on the same client throws; dispose the old session before replacing it.
98
+
99
+ ```ts
100
+ const session = remedia.createDiscordSession({
101
+ guildId,
102
+ channelId,
103
+ userId,
104
+ selfDeaf: true,
105
+ selfMute: false,
106
+ volume: 0.75,
107
+ filterGraph: 'bass=gain=3',
108
+ });
109
+ await session.connect();
110
+ await session.move(otherChannelId);
111
+ await session.setSelfDeaf(false);
112
+ await session.setSelfMute(true);
113
+ await session.dispose();
114
+ ```
115
+
116
+ `selfDeaf` defaults to `true` (previously joins always sent `false`); `selfMute` defaults to
117
+ `false`. These flags affect Discord voice state, independently of playback pause and gain.
118
+ Setters retain values before connection and update Gateway OP 4 after joining. Unchanged values
119
+ send nothing. Joins, credential refreshes, and moves preserve the flags. Keep the library-agnostic
120
+ `send(guildId, payload)` and `receive(payload)` Gateway integration wired throughout the session.
121
+
122
+ Initial `volume` is finite linear gain from 0 through 2, default 1. `filterGraph` is a trusted raw
123
+ FFmpeg audio filtergraph or `null` (default). Invalid gain and empty/non-string graphs are rejected
124
+ at creation; native FFmpeg validates graph syntax when the backend is allocated/configured, before
125
+ playback is allowed. Configuration is serialized with runtime setters and applied before audio
126
+ starts. Both values persist across tracks and transport replacement; existing `setVolume()` and
127
+ `filters.set()`/`clear()` remain available with their existing change events.
128
+
129
+ `move(channelId): Promise<void>` requests fresh Gateway credentials and replaces the existing voice
130
+ transport without restarting or seeking playback. Decoder input (including one-shot Readables),
131
+ filters, gain, playback generation, and paused state are retained. A move to the current destination
132
+ shares a pending connection or resolves immediately when connected. A newer destination supersedes
133
+ a pending attempt with an `AbortError`; `connect()` shares the latest attempt. Moving while explicit
134
+ disconnection or disposal is underway rejects. `disconnect()`/`dispose()` cancel a pending move.
135
+ `channelId` reports the latest requested destination, including after a failed move.
136
+
137
+ Intentional moves do not use the automatic recovery retry policy. A failed move reports a failed
138
+ voice state and leaves playback parked with bounded buffering; call `connect()` to retry the
139
+ requested destination, `move()` to choose another, or `disconnect()`/`dispose()` to release it.
140
+ Ordinary transport recovery retains its existing bounded credential-refresh retries. Transport
141
+ replacement itself does not emit playback stopped/completed/failed events.
142
+
143
+ Gateway mocks verify orchestration and local native tests verify media lifecycles. Real Discord
144
+ channel movement, same-channel multi-bot voice, credential ordering, and self flags still require
145
+ an application integration test with Discord. Forward only each bot's own Gateway dispatch stream.