
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.
Library for better handling WebSocket interactions and waiting for response messages
Simplifies communication over WebSocket.
Serialization/Deserialization out of the box
More structured way to exchange messages (separates type
from payload
)
waitSocket.sendMessage('MESSAGE_TYPE', { somePayload: 'example' });
Convenient way to handle incoming messages:
waitSocket.on('MESSAGE_TYPE', (payload) => doSomething(payload));
Ability to use a request/response paradigm with WebSockets (mechanism described below):
const { payload } = await waitSocket.sendRequest('MESSAGE_TYPE', requestPayload);
Flexible message format customization
Fully TypeScript
npm i waitsocket
or
yarn add waitsocket
import WaitSocket from 'waitsocket';
const waitSocket = new WaitSocket('ws://my.websocket.server:9000');
Or you can use it with your own instance of WebSocket, and even with some extends like RobustWebSocket:
const ws = new RobustWebSocket('ws://my.websocket.server:9000');
const waitSocket = new WaitSocket(ws);
If you wish to use your own message format, you can do it by extending WaitSocket class and overriding these functions, responsible for message construction and parsing:
addType(messageObject: PlainObject, type: string)
- Returns message object with type in it.getType(messageObject: PlainObject): string
- Returns message type.addPayload(messageObject: PlainObject, payload?: any)
- Returns message object with payload in it.getPayload(messageObject: PlainObject): any
- Returns message payload.addRequestId(messageObject: PlainObject, requestId?: string)
- Returns message object with requestId meta data.getRequestId(messageObject: PlainObject)
- Returns message requestId meta data.Example (use body
parameter instead of payload
):
class myWaitSocket extends WaitSocket {
protected addPayload(messageObject: PlainObject, payload?: PlainObject) {
if (!body) {
return { ...messageObject };
}
return {
...messageObject,
body: payload,
};
}
public getPayload(messageObject: PlainObject) {
return messageObject.body;
}
}
FAQs
Library for better handling WebSocket interactions and waiting for response messages
The npm package waitsocket receives a total of 0 weekly downloads. As such, waitsocket popularity was classified as not popular.
We found that waitsocket 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.