
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
ws-messaging
Advanced tools
Just a really thin abstraction layer on top of WebSocket for Node.js and Web browsers with a Promises and EventEmitter based APIs.
Send and receive notifications (events) via an EventEmitter API.
Request-reply API using promises (works in both directions, without any connection blocking during processing).
Built-in auth via WebSocket messages exchange (no more query strings).
Auto reconnection is provided.
Binary messages support via custom encoders/decoders.
Reasonable client size (also includes a Promise polyfill): around 16KB minified, 5KB gziped.
npm i ws-messaging
On a server:
const Server = require('ws-messaging')
const port = 8000
function connectionHook (client, authData) {
// check an authData
// then assign client events handlers
// return a promise
}
let server = new Server({port}, {connectionHook})
On a client:
const Client = require('ws-messaging/client')
const url = `ws://${HOST}:${PORT}`
const auth = { /* will be authData in connectionHook */ }
let client = new Client(url, auth)
client.on('someEvent', (...data) => { /* do smth */ })
client.register('someMethod', (...args) => { /* do smth, return a promise */ })
client.on('connection', () => {
/* now this client can send messages */
client.send('myEvent', ...someData)
/* or use request-reply (RPC) API */
client.invoke('myMethod', ...someArgs)
.then(result => { /* do smth */ })
.catch(error => { /* do smth */ })
})
See tests in test/index.js
for more usage examples.
Server API and Client API documentation is available online.
If you encounter a bug in this package, please submit a bug report to github repo issues.
PRs are also accepted.
MIT
FAQs
A minimalistic abstraction layer for websockets.
The npm package ws-messaging receives a total of 1 weekly downloads. As such, ws-messaging popularity was classified as not popular.
We found that ws-messaging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.