A WebSocket client library providing a Promise-based API for connecting, disconnecting, and messaging with servers. Version 3.0.1 is the latest stable release. It supports both browser and Node.js environments with ESM and CommonJS modules. Key differentiators include built-in TypeScript types, support for raw, JSON, and binary data, and a request/response pattern. The library is actively maintained and requires a global Promise constructor or polyfill for older environments.
npm install websocket-as-promisedNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a WebSocket client with JSON packing, send a request and await response, then close connection.
Set extractMessageData: event => event in constructor options.
Define packMessage and unpackMessage options for automatic request/response tracking, or implement timeout logic.
Install 'es6-promise' or similar polyfill, or use Node.js >=10 which includes native Promise.
Migrate from `wsp.onOpen.addListener(...)` to `wsp.onStatusChange.addListener(...)` or handle via `await wsp.open()`.
Add extractMessageData: event => event to constructor options.
Check wsp.isOpening or handle connection state before calling open().
Ensure server sends a response with the same ID, or implement custom timeout logic using Promise.race.