mirror of
https://github.com/karl0ss/orvibo-b25-server-kex.git
synced 2025-05-19 21:16:20 +01:00
Update Example.js to show how to pass through settings
This commit is contained in:
parent
fab292a1ae
commit
2092ead277
14
Example.js
14
Example.js
@ -4,7 +4,19 @@ const url = require('url');
|
||||
|
||||
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;
|
||||
orvbio.on('plugConnected', ({uid, name}) => {
|
||||
|
@ -13,18 +13,17 @@ let LOG_PACKET = socketSettings.LOG_PACKET;
|
||||
|
||||
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) {
|
||||
// Allow user to pass in settings
|
||||
if (userSettings != null) {
|
||||
socketSettings = userSettings;
|
||||
ORVIBO_KEY = socketSettings.ORVIBO_KEY;
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user