A general-purpose WebSocket client with extensible commands and events functionality.
- WebSocket Connection Management: Connect, disconnect, auto-reconnect with configurable delays
- Real-time Logging: Comprehensive logging with filtering (info/warn/error), export, and download capabilities
- Action System: Extensible action registry for custom commands
- Theme Support: Dark mode with theme toggle
- Local Storage: Persistent settings and connection history
- Reusable Effects: Countdown animation component for custom actions
Simply open index.html in a modern web browser. No build step or dependencies required.
- Enter your WebSocket URL (e.g.,
ws://localhost:8080/wsorwss://example.com/socket) - Click Connect
- Use the action buttons to send messages or interact with your server
The app exposes a public API for customization:
// Access the public API
const { Actions, Log, Storage, Countdown, App } = window.WebSocketClientApp;
// Define custom actions
Actions.define('custom:led-on', (ctx) => {
ctx.log.info('Turning LED on');
ctx.ws.send('led:on');
});
Actions.define('custom:countdown-demo', async (ctx) => {
await Countdown.show(document.querySelector('#countdown'), () => {
ctx.log.info('Countdown complete!');
ctx.ws.send('start:process');
});
});
// Add custom action buttons in HTML
// <button class="action" data-action="custom:led-on">
// <svg class="icon"><use href="#i-power"></use></svg>
// <span>LED On</span>
// </button>- Actions: Define and run custom actions
Actions.define(name, handler)- Register a new actionActions.run(name, ctx, element)- Execute an action
- Log: Logging utilities
Log.info(msg),Log.warn(msg),Log.error(msg)Log.rx(msg),Log.tx(msg)- Log received/transmitted messagesLog.clear(),Log.copyAll(),Log.download()
- Storage: LocalStorage wrapper
Storage.get(key, fallback),Storage.set(key, value),Storage.del(key)
- Countdown: Reusable countdown effect
Countdown.show(element, onComplete)- Display countdown animation
- App: Core application state and methods
App.connect(),App.disconnect()App.state- Current application stateApp.ws- WebSocket client instance
The client expects messages in key:value format (no spaces). Built-in handlers:
log:message- Logged as infowarn:message- Logged as warningerror:message- Logged as error
All other formats are logged as raw messages.
- Pure Vanilla JS: No frameworks or build tools required
- Single File App: All logic in
app.js, styles inline inindex.html - Modular Design: Clear separation of concerns (WSClient, Actions, Log, UI, Storage)
- Event-Driven: Actions system for extensibility
To add your own functionality:
- Define custom actions using
Actions.define() - Add corresponding buttons in the HTML with
data-actionattributes - Handle custom message formats in
App.handleWSMessage() - Use the countdown effect for timed actions
- Persist custom settings using
Storage
Works in all modern browsers that support:
- WebSocket API
- ES6+ JavaScript
- CSS Grid and Flexbox
- LocalStorage
See repository for license information.