Registry / messaging / zpusher-client

zpusher-client

JSON →
library1.0.9jsnpmunverified

ZPusher Client (v1.0.9) is a WebSocket client library for connecting to ZPusher servers. It provides an event-driven API with automatic reconnection, channel subscription, and promise-based connection management. The library ships as a single JavaScript file supporting both Node.js and browser environments via script tag or npm. Key features include configurable auto-connect, reconnect timeout, and support for custom event listeners (open, close, error, reconnect). The package has no additional dependencies but requires a valid token and WebSocket endpoint. Compared to alternatives like Socket.IO, ZPusher is minimal and focused specifically on ZPusher server protocol.

npm install zpusher-client
INSTALL
IMPORT
SIG · ZPUSHER-CLIENT
Z
zpusher-client
messagingjavascriptv1.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ZPusher
import ZPusher from 'zpusher-client'
const ZPusher = require('zpusher-client')
Library uses default export. CommonJS require may not work depending on your bundler; prefer ES module import for consistency.
default export
<script src="./node_modules/zpusher-client/dist/zpusher.js"></script>
In browser, include the dist/zpusher.js script. The global ZPusher constructor becomes available without any import statement.
TypeScript types
import { ZPusher } from 'zpusher-client'
The package does not ship TypeScript type definitions. Use @types or declare module manually. Named import with braces will fail.

Initializes ZPusher with endpoint and token, connects, subscribes to a channel, and listens for events.

import ZPusher from 'zpusher-client'; const endpoint = process.env.WS_ENDPOINT ?? 'wss://example.com/zpusher'; const token = process.env.TOKEN ?? 'your-access-token'; const pusher = new ZPusher({ endpoint, token, autoconnect: true, reconnect: true, reconnectTimeout: 30 }); pusher.on('open', () => { console.log('Connected'); pusher.subscribe('broadcast').then(onEvent => { console.log('Subscribed to broadcast channel'); // Listen for incoming messages pusher.onEvent('broadcast', data => { console.log('Received:', data); }); }).catch(err => { console.error('Subscription failed:', err); }); }); pusher.on('close', event => console.log('Connection closed:', event)); pusher.on('error', event => console.error('Error:', event));
Debug
Known issues
gotchaThe onEvent method is only available after a successful subscribe() call. Calling it before subscription will not bind to any channel.
fix
Always chain onEvent within the subscribe()'s .then() callback, not before.
affects: >=1.0
gotchaThe library does not handle token expiration or renewal. If the token expires mid-session, the connection will close with error.
fix
Implement custom token refresh logic by listening to the 'close' event and re-initializing with a new token.
affects: >=1.0
breakingIn browser environments, the constructor expects a global WebSocket object. If WebSocket is not available (e.g., old browsers), the library will throw.
fix
Use a polyfill or ensure modern browser support.
affects: >=1.0
deprecatedThe 'reconnect' and 'reconnectTimeout' options are passed in constructor but not explicitly documented in all versions; behavior may change in future.
fix
Rely on current implementation but be prepared for changes. Monitor release notes.
affects: >=1.0
Errors
Common errors & fixes
Uncaught ReferenceError: ZPusher is not defined
Attempting to use ZPusher in browser without including the dist script or using ES module import incorrectly.
fix
Ensure you include <script src='./node_modules/zpusher-client/dist/zpusher.js'></script> before using ZPusher.
Cannot read properties of undefined (reading 'then')
Calling subscribe() without having a connection (not in 'open' event handler).
fix
Always call subscribe() inside the pusher.on('open', ...) callback.
TypeError: pusher.onEvent is not a function
Attempting to call onEvent() before subscribe() has resolved.
fix
Use onEvent only inside the .then() callback of subscribe().
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
40
OpenAI (training)
1
Resources
zpusher-client — npm install zpusher-client · libregistry