The Diffusion JavaScript Client is a comprehensive library for interacting with Diffusion servers (on-premise or Diffusion Cloud) from both browser and Node.js environments. It enables real-time data streaming, pub/sub messaging, and management of topic trees over WebSockets or HTTP. Currently stable at version 6.12.1, the library typically sees regular updates, with minor versions being backward-compatible, while major versions (e.g., v5 to v6) often introduce breaking changes that require client application updates. Key differentiators include its robust support for diverse topic types, built-in TypeScript definitions, and modular bundles for optimized loading, alongside its use of Promises for asynchronous operations. It is designed for applications requiring high-performance, secure, and scalable real-time data distribution infrastructure.
npm install diffusionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to a Diffusion server, subscribe to a JSON topic, and receive real-time updates. It also shows how to publish a message to the topic, handling connection errors and ensuring proper session closure.
Review the official Diffusion documentation's 'Upgrading from version 5.x to version 6.0' guide. Recompile server-side components. Refactor client-side code to use the Unified API and supported topic types.
For browser applications, include `browserify-zlib-0.2.0.js` in your build process or use a polyfill library if working within a modern framework. For Node.js, no action is typically needed.
Thoroughly test topic selectors in both client and server environments. Simplify regular expressions where possible or use exact topic paths to minimize discrepancies. Consult Diffusion documentation on regular expression behavior.
Design client applications to gracefully handle disconnections and reconnections. Implement logic for re-establishing subscriptions, re-creating topics, and re-registering handlers upon reconnection.
Remove any usage of the `ServerStatisticsConfig` API or `server-statistics` elements from `Statistics.xml` in your Diffusion server configuration and custom applications.
Verify the `host`, `port`, `principal`, and `credentials` parameters in your `diffusion.connect()` call. Ensure the Diffusion server is running and network accessible. Check server logs for connection attempts and authentication failures.
When using modular bundles, ensure that all required feature bundles are dynamically loaded *after* the `diffusion-core.js` bundle if you need features beyond basic subscription and value streams. Alternatively, use the full `diffusion.js` bundle if bundle size is not a critical concern.
Log the `SessionError` details, including the message and any `cause` property. Consult the Diffusion server logs for more information about the underlying issue. It is often appropriate to close the current session and attempt to reconnect.