Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pusher Channels example
const Pusher = require("pusher");
const pusher = new Pusher({
appId: "APP_ID",
key: "APP_KEY",
secret: "APP_SECRET",
cluster: "APP_CLUSTER"
});
pusher.trigger("user-123", "notifications", {
message: "hello world"
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pusher Example</title>
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
</head>
<body>
<script>
const pusher = new Pusher('APP_KEY', {
cluster: 'APP_CLUSTER'
});
const channel = pusher.subscribe('user-123');
channel.bind('notifications', data => {
alert('New Notification: ' + data.message);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment