mirror of
https://github.com/karl0ss/orvibo-b25-server-kex.git
synced 2025-04-29 12:53:40 +01:00
Moves settings into constructor to allow users to set at runtime
This commit is contained in:
parent
facb5d4c34
commit
fab292a1ae
28
Orvibo.js
28
Orvibo.js
@ -6,15 +6,27 @@ const Utils = require('./Utils');
|
|||||||
const Settings = require('./OrviboSettings');
|
const Settings = require('./OrviboSettings');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
const ORVIBO_KEY = Settings.ORVIBO_KEY;
|
let socketSettings = Settings;
|
||||||
const LOG_PACKET = Settings.LOG_PACKET;
|
|
||||||
|
let ORVIBO_KEY = socketSettings.ORVIBO_KEY;
|
||||||
|
let LOG_PACKET = socketSettings.LOG_PACKET;
|
||||||
|
|
||||||
|
let PLUG_INFO = Settings.plugInfo;
|
||||||
|
|
||||||
if (ORVIBO_KEY === '') {
|
if (ORVIBO_KEY === '') {
|
||||||
console.log('Please add Orvibo PK key to OrviboSettings.js file. See Readme');
|
console.log('Please add Orvibo PK key to OrviboSettings.js file. See Readme');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Orvibo = function() {};
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Object.assign(Orvibo.prototype, EventEmitter.prototype);
|
Object.assign(Orvibo.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
@ -28,16 +40,11 @@ let UNKNOWN_CMD = 'UNKNOWN_CMD';
|
|||||||
let port = 10001;
|
let port = 10001;
|
||||||
let bindHost = '0.0.0.0';
|
let bindHost = '0.0.0.0';
|
||||||
|
|
||||||
console.log(`Starting server Orvibo socket server on port ${port}`);
|
|
||||||
|
|
||||||
let plugConnections = [];
|
let plugConnections = [];
|
||||||
let packetData = {};
|
let packetData = {};
|
||||||
|
|
||||||
// Put your smart socket data here and it will be matched to the uid
|
|
||||||
let plugInfo = Settings.plugInfo;
|
|
||||||
|
|
||||||
let getNameForUid = (uid) => {
|
let getNameForUid = (uid) => {
|
||||||
let item = plugInfo.find(item => item.uid === uid);
|
let item = PLUG_INFO.find(item => item.uid === uid);
|
||||||
return item != null ? item.name : 'unknown';
|
return item != null ? item.name : 'unknown';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,9 +127,10 @@ Orvibo.prototype.handlers = function() {
|
|||||||
Orvibo.prototype.startServer = function() {
|
Orvibo.prototype.startServer = function() {
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
let handlers = this.handlers();
|
let handlers = this.handlers();
|
||||||
|
|
||||||
|
console.log(`Starting server Orvibo socket server on port ${port}`);
|
||||||
|
|
||||||
this.server = net.createServer(function(socket) {
|
this.server = net.createServer(function(socket) {
|
||||||
|
|
||||||
socket.id = Utils.generateRandomTextValue(16);
|
socket.id = Utils.generateRandomTextValue(16);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "orvibo-b25-server",
|
"name": "orvibo-b25-server",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "A server to control the Orvibo B25 range of smart sockets",
|
"description": "A server to control the Orvibo B25 range of smart sockets",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user