Create a gist now

Instantly share code, notes, and snippets.

Embed
Node.js script to publish location and heading events to Pusher every two seconds
const Pusher = require('pusher');
const pusher = new Pusher({
appId: 'YOUR_PUSHER_APP_',
key: 'YOUR_PUSHER_APP_KEY',
secret: 'YOUR_PUSHER_APP_SECRET',
cluster: 'YOUR_PUSHER_APP_CLUSTER',
encrypted: true
});
const locations = [
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""},
{latitude: "", longitude: "-", heading: ""}
];
locations.forEach((loc, index) => {
setTimeout(() => {
console.log(loc);
pusher.trigger('private-channel', 'client-new-location', loc);
}, 2000*index);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment