Skip to content

Instantly share code, notes, and snippets.

@razvanstatescu
Created November 19, 2020 16:49
Show Gist options
  • Save razvanstatescu/88729abf039a7069764c59144e4d3202 to your computer and use it in GitHub Desktop.
Save razvanstatescu/88729abf039a7069764c59144e4d3202 to your computer and use it in GitHub Desktop.
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