{"library":"rsocket-websocket-server","title":"RSocket WebSocket Server","description":"rsocket-websocket-server provides a robust implementation of an RSocket server that operates over the WebSocket protocol, enabling reactive, multiplexed, and message-driven communication between applications. As part of the rsocket-js monorepo, it integrates seamlessly with other RSocket.js components like rsocket-core for protocol handling and various adapters. Currently, the package is in an alpha state, with 0.0.29-alpha.0 being its latest version, indicating ongoing development and pre-production readiness. The release cadence is tied to the broader rsocket-js monorepo development, which saw a significant TypeScript migration in 1.0.0-alpha.1 across its packages. Its key differentiator is offering a full RSocket server implementation specifically for WebSocket connections, adhering to the RSocket specification for high-performance, resilient, and responsive microservices and real-time applications.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rsocket-websocket-server"],"cli":null},"imports":["import { RSocketWebSocketServer } from 'rsocket-websocket-server';","import { RSocketServer, Payload, Responder } from 'rsocket-core';","import { Single, Flowable } from 'rsocket-flowable';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { RSocketServer, Payload, Responder } from 'rsocket-core';\nimport { RSocketWebSocketServer } from 'rsocket-websocket-server';\nimport { Flowable, Single } from 'rsocket-flowable';\n\nconst port = process.env.PORT ?? 8080;\n\nclass MyResponder implements Responder {\n  fireAndForget(payload: Payload): void {\n    console.log(`Received fire and forget: ${payload.data?.toString()}`);\n  }\n\n  requestResponse(payload: Payload): Single<Payload> {\n    console.log(`Received request-response: ${payload.data?.toString()}`);\n    return Single.of({\n      data: Buffer.from(`Response to ${payload.data?.toString()}`),\n      metadata: payload.metadata,\n    });\n  }\n\n  requestStream(payload: Payload): Flowable<Payload> {\n    console.log(`Received request-stream: ${payload.data?.toString()}`);\n    return Flowable.just(\n      { data: Buffer.from('Stream Item 1') },\n      { data: Buffer.from('Stream Item 2') },\n      { data: Buffer.from('Stream Item 3') }\n    ).delayElements(500); // Simulate some delay\n  }\n\n  requestChannel(payloads: Flowable<Payload>): Flowable<Payload> {\n    console.log(`Received request-channel setup payload:`);\n    return payloads.map(p => {\n      console.log(`Channel data: ${p.data?.toString()}`);\n      return {\n        data: Buffer.from(`Echo: ${p.data?.toString()}`),\n        metadata: p.metadata,\n      };\n    });\n  }\n}\n\nconst server = new RSocketServer({\n  transport: new RSocketWebSocketServer({ port }),\n  responder: new MyResponder(),\n});\n\nserver.start().then(() => {\n  console.log(`RSocket WebSocket Server started on port ${port}`);\n  console.log('Use Ctrl+C to stop');\n}).catch(error => {\n  console.error('Server failed to start:', error);\n});\n\nprocess.on('SIGINT', () => {\n  server.shutdown().then(() => {\n    console.log('Server gracefully shut down.');\n    process.exit(0);\n  }).catch(error => {\n    console.error('Error during server shutdown:', error);\n    process.exit(1);\n  });\n});","lang":"typescript","description":"This quickstart demonstrates how to set up and run an RSocket WebSocket server, handling fire-and-forget, request-response, request-stream, and request-channel interactions using the `rsocket-flowable` reactive types.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}