Skip to content

Instantly share code, notes, and snippets.

@rakibhasansabbir
Last active November 14, 2021 19:14
Show Gist options
  • Save rakibhasansabbir/acf0b0d342f0df32e9b29efb5c0ac5ca to your computer and use it in GitHub Desktop.
Save rakibhasansabbir/acf0b0d342f0df32e9b29efb5c0ac5ca to your computer and use it in GitHub Desktop.
Pusher presence channel subscription
pusher = new Pusher(process.env.PUSHER_APP_KEY, {
cluster: YOUR_PUSHER_APP_CLUSTER,
authEndpoint: YOUR_BASE_URL + '/broadcasting/auth',
auth: {
headers: {
Accept: 'application/json',
Authorization: YOUR_TOKEN
}
}
})
// debug error
pusher.connection.bind('error', function (err) {
console.debug('connection error: ', err)
})
// check connection state
pusher.connection.bind('state_change', function () {
console.debug('pusher connection state: ', pusher.connection.state)
})
// subscribe
const subscribeChannel = pusher.subscribe(YOUR_CHANNEL_NAME)
// subscription error event
subscribeChannel.bind('pusher:subscription_error', function (status) {
console.debug('subscription_error: ', status)
})
// subscription success event
subscribeChannel.bind('pusher:subscription_succeeded', function () {
console.debug('subscription_succeeded: ', subscribeChannel)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment