@students-dev/audify-js 1.0.0 → 1.0.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -310
  3. package/dist/AudioEngine.js +232 -0
  4. package/dist/cjs/index.js +1497 -1392
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/constants/index.js +35 -0
  7. package/dist/engine/Filters.js +137 -0
  8. package/dist/engine/MockAudioContext.js +53 -0
  9. package/dist/engine/Player.js +209 -0
  10. package/dist/esm/index.js +1490 -1389
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/events/EventBus.js +61 -0
  13. package/dist/index.js +18 -0
  14. package/dist/interfaces/index.js +1 -0
  15. package/dist/plugins/Plugin.js +27 -0
  16. package/dist/plugins/PluginManager.js +106 -0
  17. package/dist/providers/LavalinkProvider.js +81 -0
  18. package/dist/providers/LocalProvider.js +70 -0
  19. package/dist/providers/ProviderRegistry.js +20 -0
  20. package/dist/providers/SpotifyProvider.js +59 -0
  21. package/dist/providers/YouTubeProvider.js +48 -0
  22. package/dist/queue/Queue.js +186 -0
  23. package/dist/queue/Track.js +54 -0
  24. package/dist/types/AudioEngine.d.ts +107 -0
  25. package/dist/types/constants/index.d.ts +39 -0
  26. package/dist/types/engine/AudioEngine.d.ts +44 -1
  27. package/dist/types/engine/Filters.d.ts +25 -24
  28. package/dist/types/engine/MockAudioContext.d.ts +43 -0
  29. package/dist/types/engine/Player.d.ts +25 -21
  30. package/dist/types/events/EventBus.d.ts +17 -15
  31. package/dist/types/index.d.ts +17 -13
  32. package/dist/types/interfaces/index.d.ts +31 -0
  33. package/dist/types/plugins/Plugin.d.ts +11 -43
  34. package/dist/types/plugins/PluginManager.d.ts +19 -19
  35. package/dist/types/providers/LavalinkProvider.d.ts +17 -0
  36. package/dist/types/providers/LocalProvider.d.ts +11 -22
  37. package/dist/types/providers/ProviderRegistry.d.ts +10 -0
  38. package/dist/types/providers/SpotifyProvider.d.ts +14 -0
  39. package/dist/types/providers/YouTubeProvider.d.ts +11 -28
  40. package/dist/types/queue/Queue.d.ts +28 -22
  41. package/dist/types/queue/Track.d.ts +18 -16
  42. package/dist/types/utils/Logger.d.ts +12 -16
  43. package/dist/types/utils/Metadata.d.ts +16 -15
  44. package/dist/types/utils/Probe.d.ts +7 -7
  45. package/dist/types/utils/Time.d.ts +9 -9
  46. package/dist/utils/Logger.js +59 -0
  47. package/dist/utils/Metadata.js +90 -0
  48. package/dist/utils/Probe.js +59 -0
  49. package/dist/utils/Time.js +54 -0
  50. package/package.json +19 -9
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 @students-dev/audify-js
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,19 +1,38 @@
1
- # audify-js
1
+ # audify-js v1.0.2
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40students-dev%2Faudify-js.svg)](https://badge.fury.io/js/%40students-dev%2Faudify-js)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
6
  A lightweight, modern, modular audio engine that provides playback, filters, queue management, events, and extensibility through plugins. Works in both **Node.js** and **browser** environments.
7
7
 
8
+ **Version 1.0.2** represents a major stability and architecture enhancement, introducing a standardized provider system, robust plugin lifecycle, and full TypeScript support.
9
+
8
10
  ## Features
9
11
 
10
- - 🎵 **Unified Audio Engine**: Cross-environment abstraction using Web Audio API
11
- - 📋 **Queue Management**: Add, remove, shuffle, jump, and loop modes
12
- - 🎛️ **Audio Filters**: Bassboost, nightcore, vaporwave, 8D rotate, pitch/speed adjustment, reverb
13
- - 🔌 **Plugin System**: Extensible architecture with lifecycle hooks
14
- - 📡 **Event-Driven**: Comprehensive event system for all operations
15
- - 🌐 **Multi-Source Support**: Local files, remote URLs, YouTube, SoundCloud
16
- - 🛠️ **Developer-Friendly**: TypeScript declarations, ESM/CJS builds
12
+ - 🎵 **Unified Audio Engine**: Cross-environment abstraction using Web Audio API.
13
+ - 📋 **Advanced Queue Management**: Add, remove, shuffle, jump, loop (track/queue) modes.
14
+ - 🎛️ **Audio Filters**: Bassboost, nightcore, vaporwave, 8D rotate, pitch/speed adjustment, reverb.
15
+ - 🔌 **Robust Plugin System**: Extensible architecture with safe lifecycle hooks and error isolation.
16
+ - 📡 **Event-Driven**: Comprehensive event system for all operations.
17
+ - 🌐 **Provider Registry**: Standardized interface for providers (Local, YouTube, Spotify, Lavalink).
18
+ - 🛠️ **Developer-Friendly**: Full TypeScript support, strict typings, and ESM/CJS builds.
19
+
20
+ ## Architecture Overview
21
+
22
+ Audify-js v1.0.2 uses a modular architecture:
23
+ - **AudioEngine**: The central controller orchestrating playback, queue, and events.
24
+ - **ProviderRegistry**: Manages source providers (e.g., resolving URLs to streams).
25
+ - **Player**: Handles low-level audio context and buffer management.
26
+ - **Queue**: Manages track list and state.
27
+ - **PluginManager**: Handles extensions and hooks.
28
+
29
+ ## Documentation
30
+
31
+ For more detailed information, check out the documentation:
32
+
33
+ - [Architecture Overview](docs/ARCHITECTURE.md)
34
+ - [Providers System](docs/PROVIDERS.md)
35
+ - [Plugin Development](docs/PLUGINS.md)
17
36
 
18
37
  ## Installation
19
38
 
@@ -33,17 +52,16 @@ npm install @students-dev/audify-js
33
52
  </head>
34
53
  <body>
35
54
  <script type="module">
36
- import { AudioEngine } from '@students-dev/audify-js';
55
+ import { AudioEngine } from './dist/esm/index.js';
37
56
 
38
57
  const engine = new AudioEngine();
39
58
 
40
- engine.on('ready', () => {
59
+ engine.eventBus.on('ready', () => {
41
60
  console.log('Audio engine ready!');
42
- engine.add('https://example.com/audio.mp3');
43
- engine.play();
61
+ engine.play('https://example.com/audio.mp3');
44
62
  });
45
63
 
46
- engine.on('trackStart', (track) => {
64
+ engine.eventBus.on('trackStart', (track) => {
47
65
  console.log('Now playing:', track.title);
48
66
  });
49
67
  </script>
@@ -54,343 +72,108 @@ npm install @students-dev/audify-js
54
72
  ### Node.js
55
73
 
56
74
  ```javascript
57
- import { AudioEngine } from '@students-dev/audify-js';
75
+ import { AudioEngine, LocalProvider } from '@students-dev/audify-js';
58
76
 
59
77
  const engine = new AudioEngine();
60
78
 
61
- engine.on('ready', () => {
62
- engine.add('/path/to/audio.mp3');
63
- engine.play();
64
- });
65
- ```
66
-
67
- ## API Reference
68
-
69
- ### AudioEngine
70
-
71
- The main class that orchestrates all audio functionality.
72
-
73
- #### Constructor
74
-
75
- ```javascript
76
- const engine = new AudioEngine(options);
77
- ```
78
-
79
- #### Methods
80
-
81
- ##### Playback Controls
82
-
83
- - `play(track?)`: Play a track or resume current playback
84
- - `pause()`: Pause playback
85
- - `stop()`: Stop playback
86
- - `seek(time)`: Seek to specific time (seconds)
87
- - `setVolume(volume)`: Set volume (0-1)
88
-
89
- ##### Queue Management
90
-
91
- - `add(tracks)`: Add track(s) to queue
92
- - `remove(identifier)`: Remove track by index or ID
93
- - `next()`: Skip to next track
94
- - `previous()`: Go to previous track
95
- - `shuffle()`: Shuffle the queue
96
- - `clear()`: Clear the queue
97
- - `jump(index)`: Jump to track at index
98
-
99
- ##### Filters
100
-
101
- - `applyFilter(type, options)`: Apply audio filter
102
- - `removeFilter(type)`: Remove audio filter
103
-
104
- ##### Loop Modes
105
-
106
- - `setLoopMode(mode)`: Set loop mode (`LOOP_MODES.OFF`, `LOOP_MODES.TRACK`, `LOOP_MODES.QUEUE`)
107
-
108
- ##### State
109
-
110
- - `getState()`: Get current engine state
111
-
112
- #### Events
79
+ // Engine automatically registers default providers (Local, YouTube)
80
+ // But you can register custom ones or configure them
113
81
 
114
- - `ready`: Engine initialized
115
- - `play`: Playback started
116
- - `pause`: Playback paused
117
- - `stop`: Playback stopped
118
- - `error`: Error occurred
119
- - `queueEmpty`: Queue became empty
120
- - `trackStart`: Track started playing
121
- - `trackEnd`: Track ended
122
- - `filterApplied`: Filter applied
123
- - `trackAdd`: Track added to queue
124
- - `trackRemove`: Track removed from queue
125
- - `shuffle`: Queue shuffled
126
- - `clear`: Queue cleared
127
-
128
- ### Queue
129
-
130
- Manages the audio playback queue.
131
-
132
- ```javascript
133
- const queue = engine.queue;
134
-
135
- // Add tracks
136
- queue.add('track.mp3');
137
- queue.add(['track1.mp3', 'track2.mp3']);
138
-
139
- // Navigate
140
- queue.next();
141
- queue.previous();
142
- queue.jump(5);
143
-
144
- // Modify
145
- queue.shuffle();
146
- queue.clear();
147
- ```
148
-
149
- ### Track
150
-
151
- Represents an audio track.
152
-
153
- ```javascript
154
- import { Track } from '@students-dev/audify-js';
155
-
156
- const track = new Track('https://example.com/audio.mp3', {
157
- title: 'My Song',
158
- artist: 'Artist Name',
159
- duration: 180
82
+ engine.eventBus.on('ready', async () => {
83
+ await engine.play('./music/song.mp3');
160
84
  });
161
85
  ```
162
86
 
163
- ### Filters
164
-
165
- Apply audio effects.
87
+ ## Providers
166
88
 
167
- ```javascript
168
- // Bass boost
169
- engine.applyFilter('bassboost', { gain: 1.5 });
170
-
171
- // Nightcore
172
- engine.applyFilter('nightcore', { rate: 1.2 });
89
+ Providers allow `audify-js` to resolve and play tracks from various sources. v1.0.2 introduces a **Provider Registry**.
173
90
 
174
- // 8D Audio
175
- engine.applyFilter('8d');
176
-
177
- // Remove filter
178
- engine.removeFilter('bassboost');
179
- ```
91
+ ### Built-in Providers
180
92
 
181
- Available filters:
182
- - `bassboost`: Boost low frequencies
183
- - `nightcore`: Speed up and pitch up
184
- - `vaporwave`: Slow down and pitch down
185
- - `8d`: 8D audio rotation effect
186
- - `pitch`: Adjust pitch
187
- - `speed`: Adjust playback speed
188
- - `reverb`: Add reverb effect
93
+ - **LocalProvider**: Plays local files (Node.js) or direct URLs.
94
+ - **YouTubeProvider**: Resolves YouTube URLs (requires `ytdl-core` in real usage, mock included).
95
+ - **SpotifyProvider**: Integrates with Spotify Web API.
96
+ - **LavalinkProvider**: Connects to Lavalink nodes.
189
97
 
190
- ### Plugins
191
-
192
- Extend functionality with plugins.
98
+ ### Configuration
193
99
 
194
100
  ```javascript
195
- import { Plugin } from '@students-dev/audify-js';
196
-
197
- class MyPlugin extends Plugin {
198
- constructor() {
199
- super('my-plugin', '1.0.0');
101
+ const engine = new AudioEngine({
102
+ spotify: {
103
+ clientId: '...',
104
+ clientSecret: '...'
105
+ },
106
+ lavalink: {
107
+ host: 'localhost',
108
+ password: 'youshallnotpass'
200
109
  }
201
-
202
- onLoad(engine) {
203
- console.log('Plugin loaded!');
204
- }
205
-
206
- beforePlay(track) {
207
- console.log('About to play:', track.title);
208
- }
209
- }
210
-
211
- // Load plugin
212
- const plugin = new MyPlugin();
213
- engine.pluginManager.load(plugin);
214
- engine.pluginManager.enable('my-plugin');
215
- ```
216
-
217
- ### Providers
218
-
219
- Fetch metadata from different sources.
220
-
221
- ```javascript
222
- import { YouTubeProvider, SoundCloudProvider, LocalProvider } from '@students-dev/audify-js';
223
-
224
- // YouTube
225
- const ytInfo = await YouTubeProvider.getInfo('https://youtube.com/watch?v=VIDEO_ID');
226
-
227
- // SoundCloud
228
- const scInfo = await SoundCloudProvider.getInfo('https://soundcloud.com/artist/track');
229
-
230
- // Local file (Node.js only)
231
- const localInfo = await LocalProvider.getInfo('/path/to/file.mp3');
232
- ```
233
-
234
- ### Utils
235
-
236
- Utility functions for common tasks.
237
-
238
- ```javascript
239
- import { TimeUtils, MetadataUtils, ProbeUtils } from '@students-dev/audify-js';
240
-
241
- // Time formatting
242
- TimeUtils.format(125); // "02:05"
243
-
244
- // Metadata extraction
245
- const metadata = MetadataUtils.extract('https://example.com/song.mp3');
246
-
247
- // Audio probing
248
- const probe = await ProbeUtils.probe(audioBuffer);
249
- ```
250
-
251
- ## Examples
252
-
253
- ### Basic Playback
254
-
255
- ```javascript
256
- import { AudioEngine } from '@students-dev/audify-js';
257
-
258
- const engine = new AudioEngine();
259
-
260
- engine.on('ready', async () => {
261
- // Add tracks
262
- engine.add([
263
- 'track1.mp3',
264
- 'track2.mp3',
265
- 'https://example.com/track3.mp3'
266
- ]);
267
-
268
- // Start playing
269
- await engine.play();
270
-
271
- // Apply filter
272
- engine.applyFilter('bassboost');
273
- });
274
-
275
- // Handle events
276
- engine.on('trackStart', (track) => {
277
- console.log(`Playing: ${track.title}`);
278
- });
279
-
280
- engine.on('error', (error) => {
281
- console.error('Playback error:', error);
282
110
  });
283
111
  ```
284
112
 
285
- ### Queue Management
286
-
287
- ```javascript
288
- // Add multiple tracks
289
- engine.add([
290
- { url: 'song1.mp3', title: 'Song One' },
291
- { url: 'song2.mp3', title: 'Song Two' }
292
- ]);
293
-
294
- // Skip to next
295
- engine.next();
296
-
297
- // Shuffle queue
298
- engine.shuffle();
299
-
300
- // Clear and add new tracks
301
- engine.clear();
302
- engine.add('new-song.mp3');
303
- ```
113
+ ## Plugins
304
114
 
305
- ### Custom Plugin
115
+ Create powerful extensions using the `Plugin` class.
306
116
 
307
- ```javascript
308
- import { Plugin } from '@students-dev/audify-js';
117
+ ```typescript
118
+ import { Plugin, IAudioEngine } from '@students-dev/audify-js';
309
119
 
310
- class LoggerPlugin extends Plugin {
120
+ class MyLoggerPlugin extends Plugin {
311
121
  constructor() {
312
- super('logger');
122
+ super('logger', '1.0.0');
313
123
  }
314
124
 
315
- beforePlay(track) {
316
- console.log(`[Logger] Starting playback: ${track.title}`);
125
+ onLoad(engine: IAudioEngine) {
126
+ console.log('Plugin loaded');
317
127
  }
318
128
 
319
- afterPlay(track) {
320
- console.log(`[Logger] Finished playback: ${track.title}`);
129
+ beforePlay(track: any) {
130
+ console.log('About to play:', track.title);
321
131
  }
322
132
 
323
- trackEnd(track) {
324
- console.log(`[Logger] Track ended: ${track.title}`);
133
+ trackEnd(track: any) {
134
+ console.log('Finished:', track.title);
325
135
  }
326
136
  }
327
137
 
328
- // Register plugin
329
- const loggerPlugin = new LoggerPlugin();
330
- engine.pluginManager.load(loggerPlugin);
331
- engine.pluginManager.enable('logger');
138
+ // Register
139
+ const plugin = new MyLoggerPlugin();
140
+ engine.plugins.load(plugin);
141
+ engine.plugins.enable('logger');
332
142
  ```
333
143
 
334
- ## Browser Compatibility
144
+ ## API Reference
335
145
 
336
- - Chrome 14+
337
- - Firefox 25+
338
- - Safari 6+
339
- - Edge 12+
146
+ ### AudioEngine
340
147
 
341
- ## Node.js Compatibility
148
+ - `play(track?: ITrack | string)`: Play a track object or resolve a string (URL/ID).
149
+ - `pause()`: Pause playback.
150
+ - `stop()`: Stop playback.
151
+ - `seek(time)`: Seek to time in seconds.
152
+ - `setVolume(volume)`: 0.0 to 1.0.
153
+ - `setLoopMode(mode)`: 'off', 'track', 'queue'.
154
+ - `add(tracks)`: Add to queue.
155
+ - `next()`: Skip to next.
156
+ - `previous()`: Skip to previous.
157
+ - `shuffle()`: Shuffle queue.
158
+ - `getProvider(name)`: Get a provider instance.
342
159
 
343
- - Node.js 14+
160
+ ### Events
344
161
 
345
- For audio playback in Node.js, additional setup may be required for actual audio output.
162
+ Access via `engine.eventBus.on(event, callback)`.
163
+
164
+ - `ready`
165
+ - `play`, `pause`, `stop`
166
+ - `trackStart`, `trackEnd`
167
+ - `queueUpdate`
168
+ - `error`
346
169
 
347
170
  ## Contributing
348
171
 
349
172
  1. Fork the repository
350
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
351
- 3. Commit your changes (`git commit -m 'Add amazing feature'`)
352
- 4. Push to the branch (`git push origin feature/amazing-feature`)
353
- 5. Open a Pull Request
173
+ 2. Create feature branch
174
+ 3. Commit changes
175
+ 4. Push and PR
354
176
 
355
177
  ## License
356
178
 
357
- MIT License - see the [LICENSE](LICENSE) file for details.
358
-
359
- ## Troubleshooting
360
-
361
- ### Audio not playing in browser
362
-
363
- Ensure you're handling user interaction requirements for Web Audio API:
364
-
365
- ```javascript
366
- // Resume AudioContext on user interaction
367
- document.addEventListener('click', () => {
368
- if (engine.audioContext.state === 'suspended') {
369
- engine.audioContext.resume();
370
- }
371
- });
372
- ```
373
-
374
- ### CORS issues with remote audio
375
-
376
- When loading audio from different domains, ensure proper CORS headers are set on the server.
377
-
378
- ### Node.js audio output
379
-
380
- For actual audio playback in Node.js, you may need additional packages like `speaker` or `node-speaker`.
381
-
382
- ### Filter not working
383
-
384
- Some filters require AudioWorklet support in modern browsers. Check browser compatibility.
385
-
386
- ## Changelog
387
-
388
- ### v1.0.0
389
- - Initial release
390
- - Core audio engine
391
- - Queue management
392
- - Audio filters
393
- - Plugin system
394
- - Event system
395
- - Provider abstractions
396
- - Utility functions
179
+ MIT