
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Cross-platform interface for websockets
npm install --save cws
For node usage, look at the ws package as that's what's returned.
src/browser.js can either be loaded directly or you can require the module through browserify. Creating a server is not supported in the browser. Arguments to the constructor are passed directly to WebSocket & this module wraps around it to provide a node-style api.
const CWS = require('cws');
// or use window.CWS
// Connect to a server
const ws = CWS('ws://server/path', /* protocols, */ options);
// Checking the current state
console.log('readyState:', ws.readyState);
// Pass errors to the console
ws.on('error', e => {
console.error(e);
});
// Notify console of closure
ws.on('close', e => {
console.log('The websocket was closed');
});
// Listen for messages & log them
ws.on('message', message => {
if ('string' !== typeof message) throw Error("Message could not be decoded");
const received = JSON.parse(message);
console.log('Message received:', received);
});
// Wait for the socket to open
ws.on('open', () => {
// Say hi
ws.send(JSON.stringify({
type: 'Greeting',
data: 'Hello World',
});
// Close the socket after 5 seconds
setTimeout(() => {
ws.close();
}, 5000);
});
FAQs
Cross-platform websockets
The npm package cws receives a total of 947 weekly downloads. As such, cws popularity was classified as not popular.
We found that cws demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.