Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created May 9, 2016 19:37
Show Gist options
  • Save sibelius/6bb62d7449fc0071b729f861b0405ae4 to your computer and use it in GitHub Desktop.
Save sibelius/6bb62d7449fc0071b729f861b0405ae4 to your computer and use it in GitHub Desktop.
PubNub-cli - simulate a message from a friend
{
"presets": ["es2015", "stage-0"]
}
import 'babel-polyfill';
import program from 'commander';
import PubNub from 'pubnub';
program
.option('-c, --channel', 'Set channel')
.option('-u, --user', 'Set user')
.option('-m, --message [message]', 'Set message')
.option('-i, --image', 'Set image')
.parse(process.argv);
const channel = program.channel || '2832';
const name = program.user || 'Fry';
const text = program.message || 'hey';
const image = program.image || 'http://s19.postimg.org/kxeoh1qw3/bender.png';
const config = {
pubnub: {
ssl: true,
publish_key: 'pub-c-3329d88e-c3a6-459f-bd11-35d9eade40b6',
subscribe_key: 'sub-c-83c20e76-3bfe-11e5-a8de-0619f8945a4f',
error: (err) => console.log('PubNub error: ', err),
}
};
const pubnub = PubNub.init(config.pubnub);
const uniqueId = Math.round(Math.random() * 10000)
const message = {
date: new Date(),
image: {
uri: image,
},
name,
text,
user: 1,
uniqueId,
};
console.log(channel, message);
pubnub.publish({
channel,
message,
callback: (message) => {
console.log('pubnub publish: ', message);
process.exit();
},
error: (err) => {
console.log('pubnub error: ', err);
process.exit();
}
});
{
"name": "pubnub-cli",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "babel-node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "sibelius",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"pubnub": "^3.14.5"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-polyfill": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment