Cross-Service Integration & Testing
Cross-Service Integration
Other BANA services can send messages to Signal's WebSocket clients by creating a WebSocketEmitter that shares the same Redis connection.
Example: Payment Service
The @nx/payment package uses a WebSocketEmitter to notify clients of payment events:
// packages/payment/src/components/websocket.component.ts
const emitter = new WebSocketEmitter({
identifier: 'payment-ws-emitter',
redisConnection: redis, // Same Redis as Signal
});
await emitter.configure();// Usage in payment service
await emitter.broadcast({ event: 'payment.success', data: { orderId: '123' } });
await emitter.toClient({ clientId: 'abc', event: 'payment.status', data: { status: 'settled' } });The emitter publishes to Redis, and Signal's WebSocketServerHelper subscribes to the same channels. Messages are delivered to the appropriate WebSocket clients with automatic encryption via the outbound transformer.
Testing
Interactive Test Client
The package includes an interactive HTML test client at resources/websocket-test.html with a 3-panel layout:
Left Panel — WebSocket Controls:
- WebSocket connection management with configurable URL
- Automatic ECDH P-256 key pair generation
- JWT Bearer token authentication
- Real-time encryption/decryption with AES-256-GCM (using server-provided salt)
- Room join/leave operations
- Custom event sending (encrypted)
- Connection state, encryption status badges, and client ID display
Middle Panel — REST API Testing:
- Configurable REST base URL
- GET /status — check server readiness
- GET /clients — list all connected clients
- GET /client by ID — inspect specific client
- POST /broadcast — send to all clients
- POST /send to client — send to specific client
- POST /send to room — send to room
- POST /disconnect — force-disconnect a client
- Response display panel
Right Panel — Event Log:
- Color-coded event log (incoming, outgoing, crypto, REST, errors)
- Auto-scroll with timestamps
Open the file in a browser, configure the WebSocket URL, Bearer token, and ECDH info, then click Connect to test the full handshake and encrypted messaging flow. Use the REST API panel to test server-side message delivery.