lively 0.23.0 → 0.24.0

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.
@@ -1,174 +0,0 @@
1
- # Live.js
2
-
3
- A JavaScript client library for building interactive web applications with Ruby Live framework.
4
-
5
- [![Development Status](https://github.com/socketry/live-js/workflows/Test/badge.svg)](https://github.com/socketry/live-js/actions?workflow=Test)
6
-
7
- ## Features
8
-
9
- - **Real-time Communication**: WebSocket-based client-server communication.
10
- - **DOM Manipulation**: Efficient updating, replacing, and modifying HTML elements.
11
- - **Event Forwarding**: Forward client events to server for processing.
12
- - **Controller Loading**: Declarative JavaScript controller loading with `data-live-controller`.
13
- - **Automatic Cleanup**: Proper lifecycle management and memory cleanup.
14
- - **Live Elements**: Automatic binding and unbinding of live elements.
15
-
16
- ## Usage
17
-
18
- ### Installation
19
-
20
- ```bash
21
- npm install @socketry/live
22
- ```
23
-
24
- ### Basic Setup
25
-
26
- ```javascript
27
- import { Live } from '@socketry/live';
28
-
29
- // Start the live connection
30
- const live = Live.start({
31
- path: 'live', // WebSocket endpoint
32
- base: window.location.href
33
- });
34
- ```
35
-
36
- ### Controller Loading
37
-
38
- Live.js supports declarative controller loading using the `data-live-controller` attribute:
39
-
40
- ```html
41
- <div class="live" id="game" data-live-controller="/static/game_controller.mjs">
42
- <!-- Game content -->
43
- </div>
44
- ```
45
-
46
- ```javascript
47
- // game_controller.mjs
48
- export default function(element) {
49
- console.log('Controller loaded for:', element);
50
-
51
- // Setup your controller logic
52
- element.addEventListener('click', handleClick);
53
-
54
- // Return a controller object with cleanup
55
- return {
56
- dispose() {
57
- element.removeEventListener('click', handleClick);
58
- }
59
- };
60
- }
61
- ```
62
-
63
- ## API Reference
64
-
65
- ### Live Class
66
-
67
- #### Static Methods
68
-
69
- - `Live.start(options)` - Create and start a new Live instance
70
- - `options.window` - Window object (defaults to globalThis)
71
- - `options.path` - WebSocket path (defaults to 'live')
72
- - `options.base` - Base URL (defaults to window.location.href)
73
-
74
- #### Instance Methods
75
-
76
- ##### Connection Management
77
- - `connect()` - Establish WebSocket connection
78
- - `disconnect()` - Close WebSocket connection
79
-
80
- ##### DOM Manipulation
81
- - `update(id, html, options)` - Update element content
82
- - `replace(selector, html, options)` - Replace elements
83
- - `prepend(selector, html, options)` - Prepend content
84
- - `append(selector, html, options)` - Append content
85
- - `remove(selector, options)` - Remove elements
86
-
87
- ##### Event Handling
88
- - `forward(id, event)` - Forward event to server
89
- - `forwardEvent(id, event, detail, preventDefault)` - Forward DOM event
90
- - `forwardFormEvent(id, event, detail, preventDefault)` - Forward form event
91
-
92
- ##### Script Execution
93
- - `script(id, code, options)` - Execute JavaScript code
94
- - `loadController(id, path, options)` - Load JavaScript controller
95
-
96
- ##### Event Dispatching
97
- - `dispatchEvent(selector, type, options)` - Dispatch custom events
98
-
99
- ### Options Parameter
100
-
101
- Most methods accept an `options` parameter with:
102
- - `options.reply` - If truthy, server will reply with `{reply: options.reply}`
103
-
104
- ### Controller Pattern
105
-
106
- Controllers are JavaScript modules that manage view-specific behavior:
107
-
108
- ```javascript
109
- // Simple controller
110
- export default function(element) {
111
- // Setup code
112
- return {
113
- dispose() {
114
- // Cleanup code
115
- }
116
- };
117
- }
118
-
119
- // With options
120
- export default function(element, options) {
121
- const config = options.config || {};
122
- // Use config...
123
- }
124
- ```
125
-
126
- ## Live Elements
127
-
128
- Elements with the `live` CSS class are automatically managed:
129
-
130
- ```html
131
- <div class="live" id="my-element">
132
- Content that can be updated
133
- </div>
134
- ```
135
-
136
- ## Event Examples
137
-
138
- ### Basic Event Forwarding
139
-
140
- ```javascript
141
- // Forward click events
142
- element.addEventListener('click', (event) => {
143
- live.forwardEvent('my-element', event, { button: 'clicked' });
144
- });
145
-
146
- // Forward form submissions
147
- form.addEventListener('submit', (event) => {
148
- live.forwardFormEvent('my-form', event, { action: 'submit' });
149
- });
150
- ```
151
-
152
- ## Contributing
153
-
154
- We welcome contributions to this project.
155
-
156
- 1. Fork it.
157
- 2. Create your feature branch (`git checkout -b my-new-feature`).
158
- 3. Commit your changes (`git commit -am 'Add some feature'`).
159
- 4. Push to the branch (`git push origin my-new-feature`).
160
- 5. Create new Pull Request.
161
-
162
- ### Developer Certificate of Origin
163
-
164
- In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
165
-
166
- ### Community Guidelines
167
-
168
- This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
169
-
170
- ## See Also
171
-
172
- - [lively](https://github.com/socketry/lively) — Ruby framework for building interactive web applications.
173
- - [live](https://github.com/socketry/live) — Provides client-server communication using websockets.
174
- - [live-audio-js](https://github.com/socketry/live-audio-js) — Web Audio API-based game audio synthesis library.
@@ -1,39 +0,0 @@
1
- {
2
- "name": "@socketry/live-audio",
3
- "type": "module",
4
- "version": "0.5.1",
5
- "description": "Web Audio API-based game audio synthesis and background music library for Ruby Live applications.",
6
- "main": "Live/Audio.js",
7
- "exports": {
8
- ".": "./Live/Audio.js",
9
- "./Library": "./Live/Audio/Library.js"
10
- },
11
- "files": [
12
- "Live/"
13
- ],
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/socketry/live-audio-js.git"
17
- },
18
- "scripts": {
19
- "test": "node --test"
20
- },
21
- "devDependencies": {
22
- "jsdom": "^24.1.3"
23
- },
24
- "keywords": [
25
- "audio",
26
- "webaudio",
27
- "game",
28
- "sound",
29
- "synthesis",
30
- "music",
31
- "live"
32
- ],
33
- "author": "Samuel Williams <samuel.williams@oriontransfer.co.nz> (http://www.codeotaku.com/)",
34
- "license": "MIT",
35
- "bugs": {
36
- "url": "https://github.com/socketry/live-audio-js/issues"
37
- },
38
- "homepage": "https://github.com/socketry/live-audio-js#readme"
39
- }
@@ -1,277 +0,0 @@
1
- # Live Audio.js
2
-
3
- A Web Audio API-based game audio synthesis and background music library for Ruby Live applications.
4
-
5
- [![Development Status](https://github.com/socketry/live-audio-js/workflows/Test/badge.svg)](https://github.com/socketry/live-audio-js/actions?workflow=Test)
6
-
7
- ## Features
8
-
9
- - **Synthesized Sound Effects**: Classic game sounds including jump, coin, power-up, death, explosion, laser, and animal sounds.
10
- - **Background Music**: Audio file playback with loop points and volume control.
11
- - **Audio Visualization**: Real-time waveform display with quality monitoring.
12
- - **Anti-Clipping Protection**: Built-in gain management to prevent audio distortion.
13
- - **Modular Architecture**: Clean separation between sound synthesis, output routing, and visualization.
14
- - **Live.js Pattern Compliance**: Follows established patterns from the Live.js ecosystem.
15
-
16
- ## Usage
17
-
18
- ### Installation
19
-
20
- ```bash
21
- npm install @socketry/live-audio
22
- ```
23
-
24
- ### Basic Setup
25
-
26
- ```javascript
27
- import { Audio } from '@socketry/live-audio';
28
- import { MeowSound, ExplosionSound, BackgroundMusicSound } from '@socketry/live-audio/Live/Audio/Library.js';
29
-
30
- // Audio.start() pattern - follows Live.js conventions
31
- window.liveAudio = Audio.start();
32
-
33
- // Add sounds using the controller
34
- const meow = new MeowSound();
35
- const explosion = new ExplosionSound();
36
- const music = new BackgroundMusicSound('/assets/music.mp3', {
37
- loopStart: 10.0,
38
- loopEnd: 45.0
39
- });
40
-
41
- window.liveAudio.addSound('meow', meow);
42
- window.liveAudio.addSound('explosion', explosion);
43
- window.liveAudio.addSound('music', music);
44
- window.liveAudio.setVolume(0.8);
45
-
46
- // Play sounds anywhere in your app
47
- window.liveAudio.playSound('meow');
48
- ```
49
-
50
- ### Alternative: Direct Controller Usage
51
-
52
- ```javascript
53
- import { Audio } from '@socketry/live-audio';
54
- import { CoinSound, LaserSound } from '@socketry/live-audio/Live/Audio/Library.js';
55
-
56
- const controller = Audio.start();
57
-
58
- // Add and play sounds
59
- const coin = new CoinSound();
60
- const laser = new LaserSound();
61
- controller.addSound('coin', coin);
62
- controller.addSound('laser', laser);
63
- controller.playSound('coin');
64
- controller.setVolume(0.8);
65
- ```
66
-
67
- ## API Reference
68
-
69
- ### Audio (Main Namespace)
70
-
71
- The primary entry point following Live.js conventions.
72
-
73
- #### Static Methods
74
- - `Audio.start(options)` - Create a new controller instance (recommended)
75
- - `options.window` - The window object to use (defaults to globalThis)
76
- - Returns the controller instance
77
- - `Audio.Controller` - Direct access to Controller class for advanced usage
78
-
79
- ### Controller
80
-
81
- The main audio controller class that manages all sound playback and audio context.
82
-
83
- #### Instance Methods
84
- - `addSound(name, soundInstance)` - Add a sound instance to the controller
85
- - `playSound(name)` - Play a sound by name
86
- - `stopSound(name)` - Stop a sound by name
87
- - `stopAllSounds()` - Stop all sounds
88
- - `listSounds()` - Get array of available sound names
89
- - `removeSound(name)` - Remove a sound from the controller
90
- - `setVolume(volume)` - Set master volume (0.0 to 1.0)
91
- - `getSound(name)` - Get direct access to a sound instance
92
-
93
- ### Sound
94
-
95
- Base class for creating custom sound effects. Extend this class to create your own synthesized sounds.
96
-
97
- ```javascript
98
- import { Sound } from '@socketry/live-audio';
99
-
100
- class CustomSound extends Sound {
101
- start(output) {
102
- const audioContext = output.audioContext;
103
- const oscillator = audioContext.createOscillator();
104
- const gainNode = audioContext.createGain();
105
-
106
- oscillator.type = 'sine';
107
- oscillator.frequency.value = 440;
108
-
109
- this.createEnvelope(audioContext, gainNode, 0.01, 0.1, 0.5, 0.2, 0.5);
110
-
111
- oscillator.connect(gainNode);
112
- gainNode.connect(output.input);
113
-
114
- oscillator.start();
115
- oscillator.stop(audioContext.currentTime + 0.5);
116
- }
117
- }
118
- ```
119
-
120
- ### Visualizer
121
-
122
- Audio analysis and visualization component that provides real-time waveform display and audio quality monitoring.
123
-
124
- - Clipping detection and visualization
125
- - Audio pop/click detection
126
- - Rolling peak level monitoring
127
- - Real-time waveform display
128
-
129
- ## Built-in Sound Library
130
-
131
- The library includes a comprehensive collection of pre-built sound classes in `Library.js`:
132
-
133
- ### Game Sound Effects
134
- - `JumpSound` - Classic platform game jump sound
135
- - `CoinSound` - Collectible pickup sound
136
- - `PowerUpSound` - Power-up acquisition sound
137
- - `DeathSound` - Game over sound
138
- - `ExplosionSound` - Explosive sound with multiple rumble layers
139
- - `LaserSound` - Sci-fi laser sound
140
- - `BeepSound` - Simple notification beep
141
- - `BlipSound` - Short UI interaction sound
142
-
143
- ### Animal Sounds
144
- - `MeowSound` - Cat meow with frequency modulation
145
- - `BarkSound` - Dog bark with formant filtering
146
- - `RoarSound` - Lion roar with noise texture
147
- - `ChirpSound` - Bird chirp sound
148
- - `HowlSound` - Wolf howl with harmonic sweep
149
- - `DuckSound` - Duck quack with FM synthesis
150
- - `AlienSound` - Alien sound with ring modulation
151
-
152
- ### Background Music
153
- - `BackgroundMusicSound(url, options)` - Audio file background music with optional loop configuration
154
- - Supports common web audio formats: MP3, WAV, OGG, AAC, FLAC, and others supported by the browser
155
- - `options.loop` - Enable/disable looping (default: true)
156
- - `options.loopStart` - Loop start time in seconds
157
- - `options.loopEnd` - Loop end time in seconds
158
- - `options.volume` - Playback volume (default: 0.8)
159
-
160
- ### Usage Example
161
-
162
- ```javascript
163
- import { Audio } from '@socketry/live-audio';
164
- import { MeowSound, ExplosionSound, BackgroundMusicSound } from '@socketry/live-audio/Live/Audio/Library.js';
165
-
166
- const controller = Audio.start();
167
-
168
- // Add sounds from the library
169
- const meow = new MeowSound();
170
- const explosion = new ExplosionSound();
171
-
172
- // Background music examples:
173
- // Default: loops entire track at 80% volume
174
- const music1 = new BackgroundMusicSound('/assets/background.mp3');
175
-
176
- // Custom loop points
177
- const music2 = new BackgroundMusicSound('/assets/background.mp3', {
178
- loopStart: 10.5,
179
- loopEnd: 45.2
180
- });
181
-
182
- // No looping
183
- const music3 = new BackgroundMusicSound('/assets/background.mp3', { loop: false });
184
-
185
- // Custom volume
186
- const music4 = new BackgroundMusicSound('/assets/background.mp3', {
187
- volume: 0.6,
188
- loopStart: 5.0,
189
- loopEnd: 30.0
190
- });
191
-
192
- controller.addSound('meow', meow);
193
- controller.addSound('explosion', explosion);
194
- controller.addSound('music', music1);
195
-
196
- // Play them
197
- controller.playSound('meow');
198
- controller.playSound('explosion');
199
- controller.playSound('music');
200
- ```
201
-
202
- ## Project Structure
203
-
204
- The library follows Live.js ecosystem patterns with a clean modular architecture:
205
-
206
- ```
207
- @socketry/live-audio/
208
- ├── Live/
209
- │ ├── Audio.js # Main module - exports Controller, Sound, Visualizer
210
- │ └── Audio/
211
- │ ├── Controller.js # Audio controller with window-keyed shared instances
212
- │ ├── Sound.js # Base Sound class for custom sounds
213
- │ ├── Output.js # Audio routing and master volume control
214
- │ ├── Visualizer.js # Real-time waveform visualization
215
- │ └── Library.js # Collection of pre-built game sounds
216
- └── test/
217
- └── LiveAudio.js # Comprehensive test suite
218
- ```
219
-
220
- ### Import Patterns
221
-
222
- ```javascript
223
- // Main Audio namespace (recommended)
224
- import { Audio } from '@socketry/live-audio';
225
-
226
- // Essential classes for advanced usage
227
- import { Controller, Sound } from '@socketry/live-audio';
228
-
229
- // Full access including visualization
230
- import { Controller, Sound, Visualizer, Output } from '@socketry/live-audio';
231
-
232
- // Pre-built sound library - individual imports (recommended)
233
- import { MeowSound, ExplosionSound, BackgroundMusicSound } from '@socketry/live-audio/Live/Audio/Library.js';
234
-
235
- // Pre-built sound library - namespace import
236
- import * as Library from '@socketry/live-audio/Live/Audio/Library.js';
237
- ```
238
-
239
- ## Audio Context Management
240
-
241
- The library automatically manages a shared AudioContext to avoid browser limitations and ensure optimal performance:
242
-
243
- - Automatic context creation and resumption
244
- - Safari compatibility with proper latency handling
245
- - Shared instance pattern to prevent multiple contexts
246
- - Graceful degradation when audio is unavailable
247
-
248
- ## Browser Compatibility
249
-
250
- - Modern browsers with Web Audio API support
251
- - Handles browser autoplay policies
252
- - Safari-specific optimizations for reduced latency
253
- - Fallback behavior when audio context is unavailable
254
-
255
- ## Contributing
256
-
257
- We welcome contributions to this project.
258
-
259
- 1. Fork it.
260
- 2. Create your feature branch (`git checkout -b my-new-feature`).
261
- 3. Commit your changes (`git commit -am 'Add some feature'`).
262
- 4. Push to the branch (`git push origin my-new-feature`).
263
- 5. Create new Pull Request.
264
-
265
- ### Developer Certificate of Origin
266
-
267
- In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
268
-
269
- ### Community Guidelines
270
-
271
- This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
272
-
273
- ## See Also
274
-
275
- - [lively](https://github.com/socketry/lively) — Ruby framework for building interactive web applications.
276
- - [live](https://github.com/socketry/live) — Provides client-server communication using websockets.
277
- - [live-js](https://github.com/socketry/live-js) — JavaScript client library for Live framework.