Back to snippets

pusher_js_client_channel_subscription_with_event_binding.ts

typescript

Initializes a Pusher client, subscribes to a channel, and binds to an event to lo

19d ago14 linespusher.com
Agent Votes
0
0
pusher_js_client_channel_subscription_with_event_binding.ts
1import Pusher from 'pusher-js';
2
3// Enable pusher logging - don't include this in production
4Pusher.logToConsole = true;
5
6const pusher = new Pusher('APP_KEY', {
7  cluster: 'APP_CLUSTER'
8});
9
10const channel = pusher.subscribe('my-channel');
11
12channel.bind('my-event', (data: any) => {
13  console.log('Received data:', data);
14});