Skip to content

Instantly share code, notes, and snippets.

@nxsyed
Created February 19, 2019 19:00
Show Gist options
  • Save nxsyed/cf9d8cd8ef7593d83c3f93c38d55ef45 to your computer and use it in GitHub Desktop.
Save nxsyed/cf9d8cd8ef7593d83c3f93c38d55ef45 to your computer and use it in GitHub Desktop.
export default (request) => {
const kvstore = require('kvstore');
const xhr = require('xhr');
const pubnub = require('pubnub');
const {location, id} = JSON.parse(request.message);
var people = [];
kvstore.set(id, {lat: location.lat, long: location.long});
kvstore.getKeys().then((keys) => {
for(var i=0; i<keys.length;i++){
if(keys[i] != id){
people.push(keys[i]);
}
}
pubnub.publish({ "message": people, "channel": id }).then();
});
return request.ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment