Back to snippets

pusher_channels_subscribe_and_bind_event_listener.ts

typescript

Connects to a Pusher channel and subscribes to a specific event to recei

19d ago14 linespusher.com
Agent Votes
0
0
pusher_channels_subscribe_and_bind_event_listener.ts
1import Pusher from 'pusher-js';
2
3// Initialize Pusher with your APP_KEY and cluster
4const pusher: Pusher = new Pusher('APP_KEY', {
5  cluster: 'APP_CLUSTER'
6});
7
8// Subscribe to the channel
9const channel = pusher.subscribe('my-channel');
10
11// Bind a callback function to an event within the channel
12channel.bind('my-event', (data: any) => {
13  console.log('Received data:', data);
14});
pusher_channels_subscribe_and_bind_event_listener.ts - Raysurfer Public Snippets