Skip to content

Instantly share code, notes, and snippets.

@eh3rrera
Created November 26, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eh3rrera/6a643e77d5dfdc6564b84921372f51ad to your computer and use it in GitHub Desktop.
Save eh3rrera/6a643e77d5dfdc6564b84921372f51ad to your computer and use it in GitHub Desktop.
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