
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ws-realtime-client
Advanced tools
Lightweight, simple-to-use library for streaming realtime data to clients via WebSockets. Client Version.
ws-realtime-client is a WebSocket-based library designed to connect to the ws-realtime backend API and provide real-time updates of subscribed datamodels. The library is lightweight and easy to integrate into any frontend project (e.g., React, Preact). It decouples all WebSocket logic from UI, making it reusable across different projects and frameworks.
This package provides utilities for:
The data state is always up-to-date with real-time streaming from the backend WebSocket server. This allows frontend applications to dynamically reflect any changes without additional polling.
To install the library in your project, use:
npm install ws-realtime-client
Here’s an example of how to use the ws-realtime-client package in your project:
import {
connect,
disconnect,
subscribe,
unsubscribe,
listDatamodels,
getData,
getDatamodelData,
getSubscribedDatamodels,
getClientUUID,
onStateChange,
onWebSocketEvent,
offStateChange,
offWebSocketEvent,
} from 'ws-realtime-client';
// Connect to WebSocket server
connect('ws://localhost:3002/realtime');
// Subscribe to a datamodel
subscribe('Chargers').then(() => {
console.log('Subscribed to Chargers datamodel');
});
// Get data for all subscribed datamodels
const allData = getData();
console.log(allData);
// Get data for a specific datamodel
const chargersData = getDatamodelData('Chargers');
console.log(chargersData);
// List available datamodels from the server
listDatamodels().then((models) => {
console.log('Available datamodels:', models);
});
// Listen to state changes (e.g., when new data arrives)
onStateChange(() => {
const updatedData = getData();
console.log('Data updated:', updatedData);
});
// Listen to WebSocket events (e.g., connection open, close)
onWebSocketEvent('open', () => {
console.log('WebSocket connection opened.');
});
// Unsubscribe from a datamodel
unsubscribe('Chargers').then(() => {
console.log('Unsubscribed from Chargers datamodel');
});
// Disconnect from WebSocket server
disconnect();
connect(url: string): void
url: The WebSocket server URL (e.g., 'ws://localhost:3002/realtime'). connect('ws://localhost:3002/realtime');
disconnect(): void
disconnect();
subscribe(datamodel: string): Promise<boolean>
datamodel: The name of the datamodel to subscribe to (e.g., 'Chargers'). subscribe('Chargers').then(() => {
console.log('Subscribed to Chargers');
}).catch((err) => {
console.error('Failed to subscribe:', err);
});
unsubscribe(datamodel: string): Promise<boolean>
datamodel: The name of the datamodel to unsubscribe from (e.g., 'Chargers'). unsubscribe('Chargers').then(() => {
console.log('Unsubscribed from Chargers');
}).catch((err) => {
console.error('Failed to unsubscribe:', err);
});
listDatamodels(): Promise<string[]>
listDatamodels().then((models) => {
console.log('Available datamodels:', models);
}).catch((err) => {
console.error('Failed to list datamodels:', err);
});
getData(): object
const allData = getData();
console.log(allData);
getDatamodelData(datamodel: string): object
datamodel: The name of the datamodel (e.g., 'Chargers'). const chargersData = getDatamodelData('Chargers');
console.log(chargersData);
getSubscribedDatamodels(): string[]
const subscribedModels = getSubscribedDatamodels();
console.log(subscribedModels);
getClientUUID(): string
const uuid = getClientUUID();
console.log('Client UUID:', uuid);
onStateChange(callback: Function): void
callback: A function that will be called when state changes (e.g., new data arrives). onStateChange(() => {
console.log('State has changed');
const updatedData = getData();
console.log('Updated data:', updatedData);
});
offStateChange(callback: Function): void
callback: The callback function to remove. const stateChangeHandler = () => {
console.log('State has changed');
};
onStateChange(stateChangeHandler);
offStateChange(stateChangeHandler);
onWebSocketEvent(event: string, callback: Function): void
open, close, message, error).event: The name of the WebSocket event (e.g., 'open', 'close', 'message', 'error').callback: The function to call when the event occurs. onWebSocketEvent('open', () => {
console.log('WebSocket connection opened');
});
onWebSocketEvent('close', () => {
console.log('WebSocket connection closed');
});
offWebSocketEvent(event: string, callback: Function): void
event: The name of the WebSocket event (e.g., 'open', 'close', 'message', 'error').callback: The function to remove. const onOpenHandler = () => {
console.log('WebSocket connection opened');
};
onWebSocketEvent('open', onOpenHandler);
offWebSocketEvent('open', onOpenHandler);
Initial, Create, Update, and Delete (ICUD) model. The message contains details about the changes in the datamodel, and this is handled internally by the library.FAQs
Lightweight, simple-to-use library for streaming realtime data to clients via WebSockets. Client Version.
The npm package ws-realtime-client receives a total of 0 weekly downloads. As such, ws-realtime-client popularity was classified as not popular.
We found that ws-realtime-client demonstrated a not healthy version release cadence and project activity because the last version was released 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.