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.

messaging
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.

Library uses default export. CommonJS require may not work depending on your bundler; prefer ES module import for consistency.

import ZPusher from 'zpusher-client'

In browser, include the dist/zpusher.js script. The global ZPusher constructor becomes available without any import statement.

<script src="./node_modules/zpusher-client/dist/zpusher.js"></script>

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 footguns
gotchaThe onEvent method is only available after a successful subscribe() call. Calling it before subscription will not bind to any channel.
gotchaThe library does not handle token expiration or renewal. If the token expires mid-session, the connection will close with error.
breakingIn browser environments, the constructor expects a global WebSocket object. If WebSocket is not available (e.g., old browsers), the library will throw.
deprecatedThe 'reconnect' and 'reconnectTimeout' options are passed in constructor but not explicitly documented in all versions; behavior may change in future.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
11 hits · last 30 days
gptbot
3
Resources