Last active
November 14, 2021 19:14
-
-
Save rakibhasansabbir/acf0b0d342f0df32e9b29efb5c0ac5ca to your computer and use it in GitHub Desktop.
Pusher presence channel subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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