rsocket-websocket-client is a JavaScript library providing a WebSocket-based RSocket client implementation primarily designed for browser environments. It is part of the broader `rsocket-js` monorepo, which aims to provide a comprehensive JavaScript implementation of the RSocket protocol. As of its current version `0.0.29-alpha.0`, it is in an active alpha development phase, indicating that it is subject to rapid changes and not yet stable for production use. RSocket is a binary protocol for application-layer communication, enabling reactive streams with models like request/response, request/stream, fire-and-forget, and channel. This client focuses specifically on the WebSocket transport, making it suitable for web applications. Its key differentiator is its adherence to the RSocket specification, offering efficient, multiplexed, and reactive communication patterns over WebSockets, in contrast to traditional REST or simpler WebSocket protocols. The release cadence is currently irregular due to its alpha status, with updates reflecting progress on the overall RSocket.js implementation.
npm install rsocket-websocket-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates connecting an RSocket client via WebSocket, performing a Request-Response interaction, and subscribing to a Request-Stream, including proper connection setup and teardown for a browser environment.
Monitor the `rsocket-js` monorepo's releases and changelogs for updates. Pin exact versions in `package.json` to prevent unexpected breaking changes.
Ensure your build setup includes a `Buffer` polyfill (e.g., in Webpack 5 config) or explicitly convert your payload data to `Uint8Array` before passing it to RSocket methods and convert `Uint8Array` responses back to string/object.
Carefully configure `dataMimeType` and `metadataMimeType` in the `RSocketClient` setup options to match the server's expectations. Common values include 'application/json', 'text/plain', 'message/x.rsocket.routing.v0', or 'message/x.rsocket.composite-metadata.v0'.
When initializing `RSocketWebSocketClient`, pass an object `{ url: 'ws://your-server', wsCreator: (url) => new WebSocket(url) }` to ensure the client can instantiate the browser's native WebSocket.Always call `.subscribe()` on `Flowable` instances for stream interactions, or use `.first().toPromise()` (if expecting a single result) for request-response patterns, ensuring you handle `onNext`, `onError`, and `onComplete` callbacks.
If using Webpack 5, add `resolve: { fallback: { 'buffer': require.resolve('buffer/') } }` to your `webpack.config.js`. Alternatively, explicitly use `new TextEncoder().encode(JSON.stringify(data))` for outgoing data and `new TextDecoder().decode(payload.data)` for incoming `Uint8Array`.Verify the RSocket server is running and accessible at the specified URL (`ws://localhost:7000/rsocket`). Check server logs for handshake errors and ensure `dataMimeType` and `metadataMimeType` are correctly configured on both client and server.
Ensure `client` is instantiated with `const client = new RSocketClient({...});` and `RSocketClient` is correctly imported as a named export from `rsocket-core`.Ensure `import { Flowable } from 'rsocket-flowable';` is present and wrap the `requestResponse` call: `await Flowable.from(rsocket.requestResponse(payload)).first().toPromise();`