Update Example.js to show how to pass through settings

This commit is contained in:
Sandy Milne 2017-10-23 19:49:29 +11:00
parent fab292a1ae
commit 2092ead277
2 changed files with 17 additions and 6 deletions

View File

@ -4,7 +4,19 @@ const url = require('url');
const httpPort = 3000; const httpPort = 3000;
let orvbio = new Orvibo(); // Create a settings object to pass PK key and map sockets to names
const settings = {
ORVIBO_KEY: '', // put your PK key here as plain text
plugInfo : [
// Add uid and a name so you can easily identify the connected sockets
{
uid :'53dd7fe74de7',
name: "Lamp in Kitchen"
},
],
};
let orvbio = new Orvibo(settings);
// When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket; // When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket;
orvbio.on('plugConnected', ({uid, name}) => { orvbio.on('plugConnected', ({uid, name}) => {

View File

@ -13,18 +13,17 @@ let LOG_PACKET = socketSettings.LOG_PACKET;
let PLUG_INFO = Settings.plugInfo; let PLUG_INFO = Settings.plugInfo;
if (ORVIBO_KEY === '') {
console.log('Please add Orvibo PK key to OrviboSettings.js file. See Readme');
process.exit(1);
}
const Orvibo = function(userSettings) { const Orvibo = function(userSettings) {
// Allow user to pass in settings // Allow user to pass in settings
if (userSettings != null) { if (userSettings != null) {
socketSettings = userSettings; socketSettings = userSettings;
ORVIBO_KEY = socketSettings.ORVIBO_KEY; ORVIBO_KEY = socketSettings.ORVIBO_KEY;
LOG_PACKET = socketSettings.LOG_PACKET; LOG_PACKET = socketSettings.LOG_PACKET;
}
if (ORVIBO_KEY === '') {
console.log('Please pass Orvibo PK key details via the constructor or add to OrviboSettings.js file. See Readme');
process.exit(1);
} }
}; };