Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
rsocket-websocket-client
Advanced tools
RSocket WebSocket client for use in browser environments
The rsocket-websocket-client is an npm package that provides a WebSocket transport for RSocket, a protocol for reactive streams. It allows for communication between client and server using WebSockets, supporting features like request/response, request/stream, fire-and-forget, and channel communication patterns.
Request/Response
This feature allows for a single request to be sent to the server and a single response to be received. The code sample demonstrates how to set up a client, connect to a server, and perform a request/response interaction.
const RSocketWebSocketClient = require('rsocket-websocket-client').default;
const { RSocketClient } = require('rsocket-core');
const client = new RSocketClient({
transport: new RSocketWebSocketClient({ url: 'ws://localhost:8080' }),
setup: { keepAlive: 60000, lifetime: 180000, dataMimeType: 'application/json', metadataMimeType: 'application/json' }
});
client.connect().subscribe({
onComplete: socket => {
socket.requestResponse({ data: 'Hello' }).subscribe({
onComplete: response => console.log('Response:', response.data),
onError: error => console.error('Request/Response Error:', error)
});
},
onError: error => console.error('Connection Error:', error)
});
Request/Stream
This feature allows for a request to be sent to the server and a stream of responses to be received. The code sample shows how to initiate a request/stream interaction and handle incoming data.
const RSocketWebSocketClient = require('rsocket-websocket-client').default;
const { RSocketClient } = require('rsocket-core');
const client = new RSocketClient({
transport: new RSocketWebSocketClient({ url: 'ws://localhost:8080' }),
setup: { keepAlive: 60000, lifetime: 180000, dataMimeType: 'application/json', metadataMimeType: 'application/json' }
});
client.connect().subscribe({
onComplete: socket => {
socket.requestStream({ data: 'Stream Request' }).subscribe({
onNext: payload => console.log('Stream Data:', payload.data),
onComplete: () => console.log('Stream Complete'),
onError: error => console.error('Request/Stream Error:', error)
});
},
onError: error => console.error('Connection Error:', error)
});
Fire-and-Forget
This feature allows for a message to be sent to the server without expecting a response. The code sample demonstrates how to send a fire-and-forget message.
const RSocketWebSocketClient = require('rsocket-websocket-client').default;
const { RSocketClient } = require('rsocket-core');
const client = new RSocketClient({
transport: new RSocketWebSocketClient({ url: 'ws://localhost:8080' }),
setup: { keepAlive: 60000, lifetime: 180000, dataMimeType: 'application/json', metadataMimeType: 'application/json' }
});
client.connect().subscribe({
onComplete: socket => {
socket.fireAndForget({ data: 'Fire-and-Forget Message' });
console.log('Message sent with Fire-and-Forget');
},
onError: error => console.error('Connection Error:', error)
});
Channel
This feature allows for bi-directional communication between client and server using a channel. The code sample shows how to set up a channel and handle data flowing in both directions.
const RSocketWebSocketClient = require('rsocket-websocket-client').default;
const { RSocketClient } = require('rsocket-core');
const { Flowable } = require('rsocket-flowable');
const client = new RSocketClient({
transport: new RSocketWebSocketClient({ url: 'ws://localhost:8080' }),
setup: { keepAlive: 60000, lifetime: 180000, dataMimeType: 'application/json', metadataMimeType: 'application/json' }
});
client.connect().subscribe({
onComplete: socket => {
const requestStream = new Flowable(subscriber => {
subscriber.onNext({ data: 'Channel Message' });
subscriber.onComplete();
});
socket.requestChannel(requestStream).subscribe({
onNext: payload => console.log('Channel Data:', payload.data),
onComplete: () => console.log('Channel Complete'),
onError: error => console.error('Channel Error:', error)
});
},
onError: error => console.error('Connection Error:', error)
});
The 'ws' package is a simple to use, blazing fast, and thoroughly tested WebSocket client and server for Node.js. Unlike rsocket-websocket-client, which is specifically designed for RSocket protocol, 'ws' provides a more general-purpose WebSocket implementation without built-in support for reactive streams.
The 'socket.io-client' package is a client-side library for Socket.IO, which enables real-time, bidirectional, and event-based communication. While it offers more features like automatic reconnection and multiplexing, it does not natively support the RSocket protocol's reactive streams model like rsocket-websocket-client.
The 'faye-websocket' package is a standards-compliant WebSocket client and server for Node.js. It provides a low-level API for WebSocket communication, similar to 'ws', but does not include the reactive streams capabilities of rsocket-websocket-client.
This package is published from the rsocket-js monorepo.
Please refer to rsocket-js on GitHub or rsocket.io for more information.
FAQs
RSocket WebSocket client for use in browser environments
The npm package rsocket-websocket-client receives a total of 152,171 weekly downloads. As such, rsocket-websocket-client popularity was classified as popular.
We found that rsocket-websocket-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.