lolka.js 0.4.3 → 0.5.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.
- package/README.md +279 -11
- package/package.json +3 -5
- package/src/client/voice/AudioPlayer.js +358 -0
- package/src/client/voice/AudioResource.js +137 -0
- package/src/client/voice/VoiceConnection.js +419 -290
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-libdatachannel.txt +373 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-libjuice.txt +373 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-libsrtp.txt +35 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-nlohmann-json.txt +21 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-node-addon-api.txt +9 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-node-api-headers.txt +21 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-openssl.txt +177 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-opus.txt +44 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-plog.txt +21 -0
- package/src/client/voice/_lolka_voice/LICENSES/LICENSE-usrsctp.txt +27 -0
- package/src/client/voice/_lolka_voice/LICENSES/THIRD-PARTY.txt +16 -0
- package/src/client/voice/_lolka_voice/MANIFEST.json +47 -0
- package/src/client/voice/_lolka_voice/_loader.js +103 -0
- package/src/client/voice/_lolka_voice/_native/linux-aarch64/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/linux-aarch64-musl/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/linux-x86_64/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/linux-x86_64-musl/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/macos-arm64/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/macos-x86_64/core.node +0 -0
- package/src/client/voice/_lolka_voice/_native/windows-x86_64/core.node +0 -0
- package/src/client/voice/_lolka_voice/_version.js +4 -0
- package/src/client/voice/_lolka_voice/caps.js +56 -0
- package/src/client/voice/_lolka_voice/core.d.ts +200 -0
- package/src/client/voice/_lolka_voice/errors.js +22 -0
- package/src/client/voice/_lolka_voice/events.js +119 -0
- package/src/client/voice/_lolka_voice/index.d.ts +226 -0
- package/src/client/voice/_lolka_voice/index.js +35 -0
- package/src/client/voice/_lolka_voice/player.js +606 -0
- package/src/client/voice/_lolka_voice/receive.js +387 -0
- package/src/client/voice/_lolka_voice/sdp.js +137 -0
- package/src/client/voice/_lolka_voice/session.js +335 -0
- package/src/client/voice/_lolka_voice/signaling.js +120 -0
- package/src/client/voice/_lolka_voice/transport.js +260 -0
- package/src/client/voice/media/OpusPlayback.js +199 -0
- package/src/client/voice/media/Receiver.js +245 -0
- package/src/client/voice/media/deps.js +27 -0
- package/src/index.js +11 -0
- package/src/structures/Guild.js +5 -2
- package/typings/index.d.mts +256 -4
- package/typings/index.d.ts +256 -4
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ CDN asset URLs. See [`NOTICE`](https://github.com/Lolka-App/lolka.js/blob/main/N
|
|
|
14
14
|
npm install lolka.js
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
**Node.js 18 or newer is required.**
|
|
17
|
+
**Node.js 18.20 or newer is required.**
|
|
18
18
|
|
|
19
19
|
## Quick Example
|
|
20
20
|
|
|
@@ -38,8 +38,25 @@ client.login('token');
|
|
|
38
38
|
## Voice
|
|
39
39
|
|
|
40
40
|
Voice works over WebRTC (lolka's voice stack, not Discord's UDP transport) and ships with the base
|
|
41
|
-
install
|
|
42
|
-
|
|
41
|
+
install. The transport is a built-in native core (libdatachannel and Opus) that sends, paces and receives packets
|
|
42
|
+
on its own native threads. Its binaries for seven platforms are inside the package, so nothing is downloaded or
|
|
43
|
+
compiled at install time (the package has no install scripts and works with `npm install --ignore-scripts` and
|
|
44
|
+
offline): Linux x64/arm64 (glibc 2.28+ and musl), macOS x64/arm64 and Windows x64. There is no libwebrtc in your
|
|
45
|
+
bot process.
|
|
46
|
+
|
|
47
|
+
On any other platform (for example Windows arm64 or FreeBSD) `require('lolka.js')` and everything except voice
|
|
48
|
+
work as usual, and voice fails with an error whose `code` is `LOLKA_VOICE_UNSUPPORTED` and whose message lists the
|
|
49
|
+
supported platforms.
|
|
50
|
+
|
|
51
|
+
Requirements:
|
|
52
|
+
|
|
53
|
+
- Node.js 18.20 or newer, macOS 11 or newer on a Mac.
|
|
54
|
+
- **UDP access to the voice servers.** There is no ICE-TCP fallback: a bot in a network without outgoing
|
|
55
|
+
UDP cannot join a voice channel.
|
|
56
|
+
- `ffmpeg` in the bot's environment to play anything other than Opus (see `inputType` below).
|
|
57
|
+
|
|
58
|
+
The API is in the spirit of `@discordjs/voice`: get a connection with `joinVoiceChannel`, play audio, and
|
|
59
|
+
(optionally) receive other participants' audio.
|
|
43
60
|
|
|
44
61
|
```js
|
|
45
62
|
const { Client, GatewayIntentBits, joinVoiceChannel } = require('lolka.js');
|
|
@@ -60,14 +77,8 @@ client.on('messageCreate', async (message) => {
|
|
|
60
77
|
adapterCreator: channel.guild.voiceAdapterCreator,
|
|
61
78
|
});
|
|
62
79
|
|
|
63
|
-
// receive other participants' audio (optional)
|
|
64
|
-
connection.on('track', (track, userId) => {
|
|
65
|
-
// `track` is a MediaStreamTrack from @roamhq/wrtc
|
|
66
|
-
console.log(`receiving audio from ${userId}`);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
80
|
await connection.awaitReady();
|
|
70
|
-
connection.play('song.mp3'); // a file path or any Readable stream (
|
|
81
|
+
connection.play('song.mp3'); // a file path or any Readable stream (encoded to Opus by ffmpeg)
|
|
71
82
|
|
|
72
83
|
connection.on('idle', () => console.log('playback finished'));
|
|
73
84
|
});
|
|
@@ -76,7 +87,188 @@ client.login('token');
|
|
|
76
87
|
```
|
|
77
88
|
|
|
78
89
|
Leave the channel with `connection.destroy()`, and stop playback (without leaving) with
|
|
79
|
-
`connection.stop()`.
|
|
90
|
+
`connection.stop()`. `connection.pause()` / `connection.resume()` (alias `unpause()`) pause and continue
|
|
91
|
+
playback. When the sound stops (pause, `stop()`, end of the source, switching to the next track) the bot sends
|
|
92
|
+
five short silence packets so the listener's decoder fades out smoothly, and then nothing at all: while paused,
|
|
93
|
+
idle, or during longer silence inside a stream there are no packets and the speaking indicator goes out. `connection.paused` tells whether playback is paused.
|
|
94
|
+
|
|
95
|
+
### Playing audio
|
|
96
|
+
|
|
97
|
+
`connection.play(input, { inputType, bitrate })`:
|
|
98
|
+
|
|
99
|
+
| option | description |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `inputType` | `'arbitrary'` (default): a path or a Readable in any format, encoded by ffmpeg to stereo Opus (20 ms frames, `bitrate` kbit/s, FEC) and streamed. `'raw'`: a Readable with headerless s16le PCM (48 kHz, stereo), encoded by ffmpeg. `'ogg/opus'` / `'webm/opus'`: a path or a Readable with Ogg/Opus or WebM/Opus, sent **without ffmpeg and without re-encoding**. `'opus'`: an object-mode Readable of ready Opus packets |
|
|
102
|
+
| `bitrate` | Encoder bitrate in kbit/s for `'arbitrary'` and `'raw'`, default `128` |
|
|
103
|
+
|
|
104
|
+
Opus packets are never decoded or re-encoded by the library. Packets that carry several 20 ms frames are split
|
|
105
|
+
into single 20 ms packets; other durations (10 ms, 40 ms and 60 ms SILK) are sent as they are and paced by their
|
|
106
|
+
real length – listeners play them fine, but the speaking indicator may not light up for those. Starting a new
|
|
107
|
+
`play()` stops the previous one.
|
|
108
|
+
|
|
109
|
+
The library keeps counters of what it sent: `connection.stats()` returns `packetsSent`, `bytesSent`, `underruns`,
|
|
110
|
+
`lateTicks`, `bursts`, `resyncs`, `silentSkipped`, `drops`, `skipped`, plus `playing`, `paused`, `subscribed`, `queuedFrames`,
|
|
111
|
+
`transportState`, `receiving` and `consumers`. Pacing runs in a native thread shared by all connections of the
|
|
112
|
+
process, so a blocked event loop does not break sound that is already queued: a block shorter than about a second
|
|
113
|
+
makes no gap for the listener (what is queued is sent on time; the source is refilled when the loop is free again).
|
|
114
|
+
`lateTicks` and `bursts` describe that native pacer.
|
|
115
|
+
|
|
116
|
+
ffmpeg is started with a lowered priority so it does not get in the way of sending. Plan for roughly one CPU core
|
|
117
|
+
per 50 voice channels when you re-encode (even more under a hard CPU limit such as a container or Kubernetes limit);
|
|
118
|
+
ready Opus (`'ogg/opus'`, `'webm/opus'`, `'opus'`) hardly loads the CPU.
|
|
119
|
+
|
|
120
|
+
### Playing one track in many channels
|
|
121
|
+
|
|
122
|
+
Radio and music bots often play the same thing in many channels at once. Calling `connection.play()` in every
|
|
123
|
+
channel reads and encodes the sound once per channel – with a hundred channels that is several CPU cores spent on
|
|
124
|
+
ffmpeg alone. A **player** reads and encodes the sound once and plays it into every channel that is subscribed to it.
|
|
125
|
+
|
|
126
|
+
The API is the one from `@discordjs/voice`: `createAudioPlayer`, `createAudioResource`, `connection.subscribe(player)`.
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const {
|
|
130
|
+
joinVoiceChannel,
|
|
131
|
+
createAudioPlayer,
|
|
132
|
+
createAudioResource,
|
|
133
|
+
AudioPlayerStatus,
|
|
134
|
+
NoSubscriberBehavior,
|
|
135
|
+
} = require('lolka.js');
|
|
136
|
+
|
|
137
|
+
// For live radio keep playing when nobody listens and tolerate short network hiccups
|
|
138
|
+
const player = createAudioPlayer({
|
|
139
|
+
behaviors: { noSubscriber: NoSubscriberBehavior.Play, maxMissedFrames: 250 },
|
|
140
|
+
});
|
|
141
|
+
player.on('error', (error) => console.error(error.message, error.resource.metadata));
|
|
142
|
+
player.on(AudioPlayerStatus.Idle, () => player.play(createAudioResource(nextTrack(), { metadata: { title: 'next' } })));
|
|
143
|
+
player.play(createAudioResource('radio.mp3', { metadata: { title: 'radio' } }));
|
|
144
|
+
|
|
145
|
+
// every channel the bot joins hears the same track
|
|
146
|
+
async function joinAndListen(channel) {
|
|
147
|
+
const connection = joinVoiceChannel({
|
|
148
|
+
channelId: channel.id,
|
|
149
|
+
guildId: channel.guild.id,
|
|
150
|
+
adapterCreator: channel.guild.voiceAdapterCreator,
|
|
151
|
+
});
|
|
152
|
+
await connection.awaitReady();
|
|
153
|
+
return connection.subscribe(player); // PlayerSubscription
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const subscriptions = new Map();
|
|
157
|
+
client.on('messageCreate', async (message) => {
|
|
158
|
+
const channel = message.member?.voice?.channel;
|
|
159
|
+
if (!channel) return;
|
|
160
|
+
if (message.content === '!radio') subscriptions.set(channel.id, await joinAndListen(channel));
|
|
161
|
+
// only this channel goes quiet, the others keep playing
|
|
162
|
+
if (message.content === '!quiet') subscriptions.get(channel.id)?.unsubscribe();
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- **One source, many channels.** `player.play()`, `pause()`, `unpause()` and `stop()` act on all subscribed channels at
|
|
167
|
+
once. When a track ends the player goes `idle`, the channels stay subscribed, and the next `player.play()` sounds in all
|
|
168
|
+
of them.
|
|
169
|
+
- **Joining late.** A channel that subscribes in the middle of a track plays it from the place the player is at now.
|
|
170
|
+
- **Per-channel control.** `subscription.unsubscribe()` (or `connection.stop()`, `connection.destroy()`) removes only that
|
|
171
|
+
channel. `connection.pause()` / `connection.resume()` pause only that channel; after `resume()` it plays from the place
|
|
172
|
+
the player is at now, what it missed is not replayed. A connection has one subscription at a time: `connection.subscribe()`
|
|
173
|
+
with another player replaces the old subscription, and with the same player returns the existing one. It returns
|
|
174
|
+
`undefined` once the connection is destroyed.
|
|
175
|
+
- **Moving.** A subscription survives a move of the channel to another voice server.
|
|
176
|
+
- **Nobody is listening.** With the default `NoSubscriberBehavior.Pause` the player pauses itself when no channel can receive
|
|
177
|
+
sound (all are paused, not connected yet, or there are none) and continues when one can: a file does not move on while
|
|
178
|
+
nobody listens, and ffmpeg stands still. `NoSubscriberBehavior.Play` keeps the clock and the source running, so a channel
|
|
179
|
+
that joins hears the live broadcast – use it for radio. `NoSubscriberBehavior.Stop` stops the player on the first moment
|
|
180
|
+
without a channel that can receive, exactly as in `@discordjs/voice`.
|
|
181
|
+
- **Live streams.** `maxMissedFrames` (default 5, as in `@discordjs/voice`) is how many frames in a row the source may be
|
|
182
|
+
late before the player stops. A live stream over a flaky network needs a larger value, otherwise the first short hiccup
|
|
183
|
+
stops the player.
|
|
184
|
+
- **A slow channel does not slow the others.** A channel that cannot keep up skips ahead to the current place;
|
|
185
|
+
`connection.stats().skipped` counts the skipped frames.
|
|
186
|
+
- **One process.** A player lives inside one process. If the bot runs in several processes (shards), create a player in
|
|
187
|
+
each: the sound is then encoded once per process, not once per channel.
|
|
188
|
+
|
|
189
|
+
`player.stats()` returns `status`, `subscribers`, `activeSubscribers`, `queuedFrames`, `framesPublished`, `underruns` and
|
|
190
|
+
`resyncs`.
|
|
191
|
+
|
|
192
|
+
`connection.play(input)` still works as before and is the short way to play into one channel. It removes the connection's
|
|
193
|
+
subscription. `connection.subscribe(player)` stops the connection's own playback (without an `'idle'` event). The
|
|
194
|
+
connection's `'playing'` and `'idle'` events belong to `connection.play()` only; for a subscribed connection watch the
|
|
195
|
+
player's events. The subscription is `connection.subscription` (the connection's `state` is a string here, so it is not
|
|
196
|
+
`state.subscription` as in `@discordjs/voice`).
|
|
197
|
+
|
|
198
|
+
Code written for `@discordjs/voice` (player, resource, `subscribe`) works as it is, apart from `require('lolka.js')`, with
|
|
199
|
+
these differences:
|
|
200
|
+
|
|
201
|
+
- **No `inlineVolume`.** It throws a `TypeError`: the library does not process sound in your process. Change the volume
|
|
202
|
+
in ffmpeg (for example `-af volume=0.5` when you start ffmpeg yourself). `StreamType.Raw` (headerless s16le PCM, 48 kHz,
|
|
203
|
+
stereo) works: ffmpeg encodes it to Opus once for all channels. A prism-media `Decoder` or `VolumeTransformer` passed
|
|
204
|
+
without `inputType` is treated as raw PCM. `resource.volume` and `resource.encoder` are always `undefined`.
|
|
205
|
+
- **A string is a path.** Without `inputType`, or with `'opus'` or `'raw'`, ffmpeg reads it (as in `@discordjs/voice`); with
|
|
206
|
+
`'ogg/opus'` or `'webm/opus'` it is read without ffmpeg.
|
|
207
|
+
- **If ffmpeg dies** (a missing file, a broken stream, the process was killed) the player emits `'error'` with the reason
|
|
208
|
+
and goes `idle`; it does not look like a normal end of the track.
|
|
209
|
+
- **A missed frame is a gap, not a frame of silence.** When the source is late the channel simply sends nothing for that
|
|
210
|
+
moment. `maxMissedFrames` counts them as in `@discordjs/voice`.
|
|
211
|
+
- **The silence tail is always five packets and belongs to each channel.** `player.pause(interpolateSilence)`,
|
|
212
|
+
`player.stop(force)` and `silencePaddingFrames` are accepted for compatibility; `stop()` always goes to `idle` at once.
|
|
213
|
+
- **Extensions:** `createAudioResource(input, { bitrate })` for `'arbitrary'` and `'raw'`, `player.stats()`, `connection.pause()` /
|
|
214
|
+
`connection.resume()` for a subscribed connection.
|
|
215
|
+
|
|
216
|
+
### Receiving audio
|
|
217
|
+
|
|
218
|
+
Receiving is off until you ask for it: the bot does not create a receive transport and does not consume anybody's
|
|
219
|
+
audio. Any of these turns it on (it then stays on until the connection moves to another voice server or is destroyed; the voice server has no way
|
|
220
|
+
to close a consumer, so the library only stops listening to participants who left):
|
|
221
|
+
|
|
222
|
+
- `joinVoiceChannel({ ..., receive: true })`;
|
|
223
|
+
- adding a `'track'` listener;
|
|
224
|
+
- calling `connection.receiver.subscribe(userId)`.
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
// Opus packets of one participant as an object-mode Readable (one Buffer = one Opus packet)
|
|
228
|
+
const opus = connection.receiver.subscribe(userId);
|
|
229
|
+
opus.on('data', (packet) => decoder.write(packet)); // decode with prism.opus.Decoder, @discordjs/opus or opusscript
|
|
230
|
+
|
|
231
|
+
// or one event per participant track
|
|
232
|
+
connection.on('track', (track, userId, producerId) => {
|
|
233
|
+
track.on('packet', (opus, { sequence, timestamp, ssrc }) => {});
|
|
234
|
+
track.on('ended', () => {});
|
|
235
|
+
// track.createReadStream() gives the same packets as a stream, track.stop() stops receiving this track
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The stream returned by `subscribe(userId)` ends when that participant's audio producer closes or the connection is
|
|
240
|
+
destroyed; it survives moves to another voice server. Participants who are already in the channel when receiving
|
|
241
|
+
is turned on are delivered right away. The library does not decode Opus; PCM is up to you. `stream.dropped` counts packets dropped because you read too slowly.
|
|
242
|
+
|
|
243
|
+
Participants that leave are closed in the receive session (`m=audio 0`), but the native media section behind each
|
|
244
|
+
of them stays in libdatachannel (about 40 KB each), so a long-running receiver would grow. Memory is bounded by
|
|
245
|
+
rebuilding instead: when more than `VoiceConnection.recvRebuildThreshold` (128 by default) participants have left,
|
|
246
|
+
the library opens a new receive transport, consumes the active participants again and switches to it. Tracks and
|
|
247
|
+
`subscribe()` streams keep working; at most a short gap in audio is possible while this happens. The old transport is
|
|
248
|
+
then closed on the voice server with the `closeTransport` signaling call so it stops sending media to a closed
|
|
249
|
+
socket; a voice server that does not know this method answers with an error, which is only written to the
|
|
250
|
+
`NODE_DEBUG=lolkajs-voice` log and never emitted as `'error'`. Consumers of participants who left are not closed
|
|
251
|
+
individually on the server; they go away with their transport or with the session.
|
|
252
|
+
|
|
253
|
+
### Process-wide state
|
|
254
|
+
|
|
255
|
+
The core starts lazily, with the first voice connection or player; before that a bot has no native voice threads.
|
|
256
|
+
It uses a fixed set of native threads (a libdatachannel pool, the pacer, the event thread) that does not depend on
|
|
257
|
+
the number of channels. The process exits on its own when the last connection is closed and nothing is playing: the
|
|
258
|
+
core holds the event loop only while a peer is open or a source is playing, so there is no global `cleanup()` to call.
|
|
259
|
+
Voice works inside `worker_threads` (for example `ShardingManager` with `mode: 'worker'`).
|
|
260
|
+
|
|
261
|
+
### Moves and reconnects
|
|
262
|
+
|
|
263
|
+
Calling `joinVoiceChannel` again for a guild that already has a live connection reuses it and moves the
|
|
264
|
+
bot via `connection.rejoin({ channelId, selfMute, selfDeaf })` (all fields optional), like `@discordjs/voice`.
|
|
265
|
+
Moving the bot between channels, or the channel being moved to another voice server, is transparent to
|
|
266
|
+
`play()`: the player is kept and playback continues on the new session. After such a move the `'track'` event fires
|
|
267
|
+
again for every participant (the old tracks end), and `ready` is still emitted only once. If the voice
|
|
268
|
+
server kicks the bot, or the connection to the voice server is lost, and no move follows within a few
|
|
269
|
+
seconds, the connection is destroyed (`state` stays `'ready'` during that grace period). A failed initial
|
|
270
|
+
start also destroys the connection, so the next `joinVoiceChannel` creates a fresh one. Connections are
|
|
271
|
+
reused per client and guild, so several clients in one process do not interfere.
|
|
80
272
|
|
|
81
273
|
`joinVoiceChannel(options)` accepts:
|
|
82
274
|
|
|
@@ -87,3 +279,79 @@ Leave the channel with `connection.destroy()`, and stop playback (without leavin
|
|
|
87
279
|
| `adapterCreator` | `Function` | `guild.voiceAdapterCreator` |
|
|
88
280
|
| `selfMute` | `boolean` | default `false` |
|
|
89
281
|
| `selfDeaf` | `boolean` | default `false` |
|
|
282
|
+
| `receive` | `boolean` | turn receiving on right away, default `false` |
|
|
283
|
+
|
|
284
|
+
Besides the events above, the connection emits `'speaking'` `(userId, speaking)` when the voice server reports that
|
|
285
|
+
a participant started or stopped talking.
|
|
286
|
+
|
|
287
|
+
### Migrating from 0.4
|
|
288
|
+
|
|
289
|
+
0.5.2 (0.5.0 and 0.5.1 were never published to npm) replaces `@roamhq/wrtc` and `mediasoup-client` with the built-in native voice core (libdatachannel and Opus). What changes for you:
|
|
290
|
+
|
|
291
|
+
- **`'track'` hands out a different object.** It used to be a wrtc `MediaStreamTrack`; it is now a `RemoteAudioTrack`
|
|
292
|
+
(an `EventEmitter`) with `userId`, `producerId`, `readyState`, the events `'packet'` `(opus, { sequence, timestamp, ssrc })`
|
|
293
|
+
and `'ended'`, and the methods `createReadStream()` and `stop()`. Code such as `new RTCAudioSink(track)` no longer works.
|
|
294
|
+
To get PCM, decode the Opus packets yourself (`prism.opus.Decoder` with `@discordjs/opus` or `opusscript`; neither is a
|
|
295
|
+
dependency of lolka.js). `connection.receiver.subscribe(userId)` is the stream-shaped alternative.
|
|
296
|
+
- **Listening to `'track'` turns receiving on.** Before, receiving was always on; now a bot that never asks for it does not
|
|
297
|
+
receive or decode anything.
|
|
298
|
+
- **UDP is required** to reach the voice servers; the ICE-TCP fallback is gone.
|
|
299
|
+
- **Node.js 18.20 or newer.**
|
|
300
|
+
- `play()` accepts a second argument (`inputType`, `bitrate`); audio is now encoded to Opus once by ffmpeg (or sent as is for
|
|
301
|
+
Opus inputs) instead of being fed to libwebrtc as PCM. After a short silence tail (five packets) the bot sends nothing while paused, idle and in silence.
|
|
302
|
+
- New: `pause()`, `resume()`, `unpause()`, `paused`, `receiver`, `stats()`, `joinVoiceChannel({ receive })`, the `'speaking'` event.
|
|
303
|
+
- New: `createAudioPlayer`, `createAudioResource` and `connection.subscribe(player)` – one track in many channels, read and encoded once (see "Playing one track in many channels").
|
|
304
|
+
- If ffmpeg cannot read the input (a missing file, a broken stream), `play()` reports `'error'` (when there is a listener) and `'idle'`.
|
|
305
|
+
- Everything else (`joinVoiceChannel`, `awaitReady`, `rejoin`, `stop`, `destroy`, `kickGraceMs` and the
|
|
306
|
+
`ready` / `playing` / `idle` / `destroyed` / `error` events) is unchanged.
|
|
307
|
+
|
|
308
|
+
### What does not map one to one
|
|
309
|
+
|
|
310
|
+
The public API of 0.5.2 and of `@discordjs/voice` is kept; these are the behaviours that differ because the work
|
|
311
|
+
moved into a native core:
|
|
312
|
+
|
|
313
|
+
- **Player events arrive asynchronously**, after the native tick that caused them, not at the end of a JS timer tick.
|
|
314
|
+
Their order is the same. A handler (for example one that starts ffmpeg on `idle`) no longer delays the packets of any
|
|
315
|
+
channel.
|
|
316
|
+
- **Received packets arrive in batches** at most every 40 ms, so reception can be up to 40 ms later. The order inside a
|
|
317
|
+
track holds. The `opus` buffer of a `'packet'` event is a slice of the shared batch buffer: copy it if you keep it.
|
|
318
|
+
- **A source error comes after the ready frames.** When ffmpeg or your Readable fails, the frames that were already
|
|
319
|
+
queued are played out first and then `'error'` and `'idle'` follow, so the error can arrive up to about two seconds
|
|
320
|
+
later than before.
|
|
321
|
+
- **`resource.started` counts packets, not 20 ms frames.** It becomes `true` after five Opus packets (or when the source
|
|
322
|
+
has ended); a packet that carries several 20 ms frames counts once.
|
|
323
|
+
- **`connection.pause()` on an idle sender returns `true`** (it was `false` before).
|
|
324
|
+
- **An empty source** (a stream that ends without a single packet) goes `buffering` -> `idle` without `playing` and
|
|
325
|
+
without an error.
|
|
326
|
+
- **No send errors from the pacer.** A failed send only increments `drops` and writes the first line to the
|
|
327
|
+
`NODE_DEBUG=lolkajs-voice` log; there is no `'error'` for it.
|
|
328
|
+
- **Platforms are the seven listed above.** Windows arm64 is not supported.
|
|
329
|
+
- **Workers.** Voice works inside `worker_threads`; there is no `cleanup()` to call and the process exits by itself.
|
|
330
|
+
|
|
331
|
+
## Configuration
|
|
332
|
+
|
|
333
|
+
`lolka.js` talks to the public lolka by default. These environment variables override the endpoints
|
|
334
|
+
(read when a client is created, no trailing slash needed):
|
|
335
|
+
|
|
336
|
+
| variable | default | description |
|
|
337
|
+
| --- | --- | --- |
|
|
338
|
+
| `LOLKA_API_BASE` | `https://lolka.app/api/bot` | Bot API base (the library appends `/v10`). The gateway URL is taken from `GET /gateway/bot` |
|
|
339
|
+
| `LOLKA_CDN` | `https://cdn.lolka.app` | CDN for avatars, banners, icons, emojis, soundboard |
|
|
340
|
+
| `LOLKA_WEB` | `https://lolka.app` | Web client, used for channel/message links and bot authorization |
|
|
341
|
+
| `LOLKA_INVITE` | `https://lolka.gg` | Base of invite links |
|
|
342
|
+
|
|
343
|
+
### CDN
|
|
344
|
+
|
|
345
|
+
The lolka CDN does no resizing and serves only webp, so the `size`, `extension` and `forceStatic`
|
|
346
|
+
options of `avatarURL()`, `iconURL()`, `bannerURL()` and friends are ignored. `client.rest.cdn` is a
|
|
347
|
+
`LolkaCDN` (exported, together with the `LolkaCDNBase`, `LolkaWebBase`, `LolkaInviteBase` and
|
|
348
|
+
`LolkaApiBase` constants, which are snapshots of the values at load time).
|
|
349
|
+
|
|
350
|
+
### Links
|
|
351
|
+
|
|
352
|
+
- `invite.url` is `https://lolka.gg/{code}`; invites are also recognised as `https://lolka.app/i/{code}`
|
|
353
|
+
- `client.generateInvite()` returns `https://lolka.app/bot-authorize?client_id=...`
|
|
354
|
+
- `webhook.url` is `https://lolka.app/api/webhooks/{id}/{token}`; `WebhookClient` accepts such URLs
|
|
355
|
+
- `channel.url` is `https://lolka.app/servers/{guild}/channels/{channel}` (DMs: `/me/channels/{channel}`),
|
|
356
|
+
`message.url` appends `/{message}`
|
|
357
|
+
- the exported `channelLink()` and `messageLink()` build the same URLs
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "lolka.js",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"description": "A powerful library for interacting with the lolka bot API (discord.js-compatible fork)",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "node ./scripts/esmDts.mjs",
|
|
8
8
|
"prepack": "npm run build",
|
|
9
|
-
"test": "node
|
|
9
|
+
"test": "node test/run.js"
|
|
10
10
|
},
|
|
11
11
|
"main": "./src/index.js",
|
|
12
12
|
"types": "./typings/index.d.ts",
|
|
@@ -53,12 +53,10 @@
|
|
|
53
53
|
"@discordjs/rest": "^2.6.1",
|
|
54
54
|
"@discordjs/util": "^1.2.0",
|
|
55
55
|
"@discordjs/ws": "^1.2.3",
|
|
56
|
-
"@roamhq/wrtc": "^0.10.0",
|
|
57
56
|
"discord-api-types": "^0.38.40",
|
|
58
57
|
"fast-deep-equal": "3.1.3",
|
|
59
58
|
"lodash.snakecase": "4.1.1",
|
|
60
59
|
"magic-bytes.js": "^1.13.0",
|
|
61
|
-
"mediasoup-client": "^3.21.0",
|
|
62
60
|
"prism-media": "^1.3.5",
|
|
63
61
|
"tslib": "^2.6.3",
|
|
64
62
|
"undici": "6.24.1",
|
|
@@ -69,7 +67,7 @@
|
|
|
69
67
|
"typescript": "~5.8.3"
|
|
70
68
|
},
|
|
71
69
|
"engines": {
|
|
72
|
-
"node": ">=18"
|
|
70
|
+
"node": ">=18.20"
|
|
73
71
|
},
|
|
74
72
|
"publishConfig": {
|
|
75
73
|
"provenance": true
|