SocketCluster Client (socketcluster-client) is the JavaScript client library for connecting to SocketCluster servers, enabling high-performance, real-time, bi-directional communication over WebSockets. It provides abstractions for pub/sub (channels), remote procedure calls (RPC), and efficient data streaming. The library is currently at version 20.0.1, indicating an active development cycle with frequent major releases that often introduce breaking changes. Key differentiators include its focus on scalability, built-in support for backpressure handling, and a clear API for consuming events and data streams using async iterators, making it suitable for demanding real-time applications like chat, gaming, and financial dashboards. It is designed to work seamlessly with `socketcluster-server`.
npm install socketcluster-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates connecting to a SocketCluster server, transmitting data, invoking an RPC, subscribing to a channel, publishing to it, and consuming messages using async iterators.
Update all references from `SCSocket` to `SCClientSocket` in your code, including type imports and class instantiations.
Review event handlers for 'authenticate' to ensure they correctly handle token changes and potential user session overrides, especially in multi-user or shared device environments.
Replace `socketClusterClient.connect(...)` with `socketClusterClient.create(...)` or `create(...)` if using named imports. While `connect` might still work, it is deprecated.
Update any references to `socketCluster.connections` to `socketCluster.clients`.
Ensure that connection options (hostname, host, port) are correctly configured and mutually exclusive where required. Refer to the official documentation for valid combinations.
Avoid using event names that are internally reserved by SocketCluster for custom transmissions. If an error is triggered, rename your custom event.
Change `socketClusterClient.connect(...)` to `socketClusterClient.create(...)`. The `connect` method was renamed in v10.0.0.
Ensure `<script type="text/javascript" src="/socketcluster-client.js"></script>` is present and accessible in your HTML, or use `import { create } from 'socketcluster-client';` (ESM) / `const { create } = require('socketcluster-client');` (CJS) at the top of your JavaScript file.Update code to use `socketCluster.clients` instead of `socketCluster.connections`. This rename occurred in v10.0.0.
Rename the custom event you are trying to transmit to avoid conflict with SocketCluster's internal event names. This behavior changed in v13.0.0.