Skip to content

Instantly share code, notes, and snippets.

@nickharris
Last active December 13, 2015 17:48
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 nickharris/4950428 to your computer and use it in GitHub Desktop.
Save nickharris/4950428 to your computer and use it in GitHub Desktop.
SensorData Insert Script
var Pusher = require('pusher');
function insert(item, user, request) {
request.execute({
success: function() {
// After the record has been inserted, trigger immediately to the client
request.respond();
// Publish event for all other active clients
publishItemCreatedEvent(item);
}
});
function publishItemCreatedEvent(item) {
// Ideally these settings would be taken from config
var pusher = new Pusher({
appId: '36277',
key: '<replace with your Pusher key>',
secret: '<replace with your Pusher secret>'
});
// Publish event on Pusher channel
pusher.trigger('sensor-updates', item.SensorID, item );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment