Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rsocket-websocket-client

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rsocket-websocket-client

RSocket WebSocket client for use in browser environments

  • 0.0.29-alpha.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
154K
increased by67.75%
Maintainers
6
Weekly downloads
 
Created

What is rsocket-websocket-client?

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.

What are rsocket-websocket-client's main functionalities?

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)
});

Other packages similar to rsocket-websocket-client

FAQs

Package last updated on 06 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc