A lightweight, type-safe wrapper around Pusher JS for subscribing to real-time events in frontend applications. Implements the Subscription interface from @schorts/shared-kernel, enabling clean, modular integration with your pub-sub architecture.
npm install @schorts/pusher-subscriptionimport { Pusher, PusherSubscription } from '@schorts/pusher-subscription';
const pusher = new Pusher('YOUR_APP_KEY', {
cluster: 'YOUR_APP_CLUSTER',
authEndpoint: '/pusher/auth',
auth: {
headers: {
Authorization: `Bearer ${yourAccessToken}`,
},
},
});
const subscription = new PusherSubscription(pusher);subscription.connect();
subscription.subscribe('private-WAITER_KITCHEN_abc123', 'order_ready', (data) => {
console.log('Order ready:', data);
});subscription.unsubscribe('private-WAITER_KITCHEN_abc123');
subscription.disconnect();This class implements the Subscription interface from @schorts/shared-kernel.
- ✅ Type-safe and framework-agnostic
- ✅ Clean separation of subscription logic from transport
- ✅ Easy to swap for other clients (e.g. Socket.IO, Ably)
- ✅ Ideal for frontend apps using modular pub-sub architecture
LGPL