How iwanni/useless-inventions-window-interaction works
1. Project shape
- This is a single-page, static browser demo with no backend, no build pipeline, and no server-side state.
- The entire app appears to live in index.html, with media assets in assets/.
2. Primary runtime boundary
- The architecture is centered on multiple browser windows/tabs running the same page.
- Each window acts as an independent client, and the “shared world” emerges from cross-window communication rather than any central service.
3. Cross-window communication
- The main coordination mechanism is BroadcastChannel.
- Windows broadcast their presence and positional data so each instance can detect the other window and react to it.
- This is the key integration boundary for the app: local window state → channel messages → remote window awareness.
4. Position and proximity model
- Each window tracks its own screen position and the other window’s position.
- The app computes distance between window centers and uses that value as the main trigger for behavior.
- The readme indicates a 510px threshold and a 100ms update cadence, so the interaction is effectively a low-frequency polling/coordination loop.
5. Interaction logic
- Far apart: Goku stays in the default state.
- Close enough: Goku switches into a powered-up / Kamehameha state.
- The window-to-window relationship therefore drives a simple state machine: idle → charging → firing/beam.
6. Orientation and mirroring
- The demo supports two roles, selected via URL parameter:
- ?w=1 for the default orientation
- ?w=2 for the mirrored orientation
- This creates a symmetric setup where one window faces right and the other faces left, making the visual interaction feel directed across the screen.
7. Audio subsystem
- The app uses three sound assets:
- charge
- fire
- beam loop/continuous beam
- Audio playback is sequenced, so the visual transition is paired with staged sound effects rather than a single one-shot clip.
8. Browser interaction requirement
- Audio is gated behind a user gesture, so the app supports click, tap, or keyboard input to unlock sound.
- This is a browser-policy boundary rather than an application-level feature, and it affects the startup flow.
9. Media/assets layer
- The repo contains only static audio files in assets/:
- kame_charge.mp3
- basicbeam_fire.mp3
- beamhead.mp3
- The readme also references animated Goku/GIF assets, which are likely embedded in the HTML or fetched from elsewhere, and serve as the visual states for the interaction.
10. User experience flow
- Open the same page in two windows.
- Assign one as w=1 and the other as w=2.
- Move the windows around the screen.
- Each window broadcasts its position, the other computes distance, and both update their visuals and audio in response.
- The result is a loosely coupled, browser-native “battle” between windows with no central coordinator.
11. Architecture summary
- Conceptually, the app has three layers:
- Presentation: Goku animation/rotation and mirrored rendering
- Coordination: BroadcastChannel-based window discovery and position exchange
- Effects: distance-triggered audio sequencing and state transitions
- This makes the app a good example of a client-only, multi-instance interactive demo built entirely on standard browser APIs.
Main entry points: index.html App page · README.md README · kame_charge.mp3 Charge sound · basicbeam_fire.mp3 Fire sound
Components 16
Presentation
Browser rendering and mirrored window layout
- App page · Single-page client entrypoint
index.html - Window roles · Selects default or mirrored orientation
- Goku view · Animated character presentation and rotation
- Mirroring · Faces opposite window directions
Coordination
Cross-window presence and position exchange
- BroadcastChannel · Cross-window message bus
- Presence sync · Announces each instance to peers
- Position sync · Shares window screen position
- Distance check · Compares window centers against threshold
- Update loop · Refreshes state about every 100ms
Effects
Distance-triggered state and audio sequencing
- Battle state · Idle, charging, and firing transitions
- Audio cues · Plays charge, fire, and beam loop
- Audio unlock · Enables playback after user interaction
Assets
Static media used by the demo
- Charge sound · Charging cue
assets/kame_charge.mp3 - Fire sound · Initial firing cue
assets/basicbeam_fire.mp3 - Beam loop · Continuous beam audio
assets/beamhead.mp3
Other components
- README · Usage and interaction notes
README.md
Connections 17
- README → App page: describes · Documents the demo flow and controls
- App page → Window roles: selects · Chooses one of two mirrored roles
- Window roles → Goku view: renders · Places the character in each window
- Window roles → Mirroring: applies · Flips orientation for the opposing window
- App page → BroadcastChannel: uses · Initializes the cross-window message bus
- BroadcastChannel → Presence sync: carries · Broadcasts instance availability
- BroadcastChannel → Position sync: carries · Broadcasts screen position updates
- Position sync → Distance check: feeds · Supplies local and remote coordinates
- Update loop → Position sync: ticks · Runs the periodic position exchange
- Distance check → Battle state: drives · Switches between idle and powered-up behavior
- Battle state → Goku view: updates · Changes the visible animation state
- Battle state → Audio cues: triggers · Starts the staged sound sequence
- Audio unlock → Audio cues: enables · Allows playback after gesture input
- Audio cues → Charge sound: plays · Charge stage sound
- Audio cues → Fire sound: plays · Fire stage sound
- Audio cues → Beam loop: loops · Sustains the beam effect
- App page → Audio unlock: listens for · Waits for click, tap, or keyboard input