An async/await WebSocket client for browsers. Version 1.3.0 provides a simple, promise-based interface for WebSocket connections using ES2017 async/await. The library wraps the native WebSocket API and offers methods like connect, send, receive, and disconnect. Unlike raw WebSocket, it queues incoming messages and allows asynchronous reading via receive() without event listeners. It supports reconnection and sends data synchronously while receiving asynchronously. The library is browser-only, has no dependencies, and is ESM-compatible.
npm install websocket-asyncNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of WebSocketClient: connect, send, receive, and disconnect using async/await.
Ensure client.connected is true before calling send().
Check client.dataAvailable > 0 before calling receive() to avoid waiting.
Use await client.disconnect() and handle potential undefined.
Use for browser apps only; for Node.js use the 'ws' library with async wrappers.
Implement custom reconnection logic using connect/disconnect loop.
Use `import { WebSocketClient } from 'websocket-async'`Use in browser or provide a polyfill like `globalThis.WebSocket = require('ws')`Ensure you created an instance: `const client = new WebSocketClient()`
Check `client.connected` and `client.dataAvailable` before calling receive.
No dependency data recorded yet.