Skip to content

Instantly share code, notes, and snippets.

@antimech
Last active May 28, 2023 06:29
Show Gist options
  • Save antimech/24ad6ce111df87c7af3490457f5ed120 to your computer and use it in GitHub Desktop.
Save antimech/24ad6ce111df87c7af3490457f5ed120 to your computer and use it in GitHub Desktop.
The frontend part of the example of using private channel with Pusher WebSocket Server and Laravel
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/4.1/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('key_here', {
cluster: 'eu',
encrypted: true,
authEndpoint: 'https://homestead.test/api/v1/broadcasting/auth',
auth: {
headers: {
'Authorization': "Bearer token_here"
}
},
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(data.message);
});
var privateChannel = pusher.subscribe('private-App.User.1'); // TODO: Change "1" for the actual user ID
privateChannel.bind('App\\Events\\ReferralRegistered', function(data) {
alert(data.referral);
});
</script>
</head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment