-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from OpenHausIO/dev
v2.1.0
- Loading branch information
Showing
36 changed files
with
2,741 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=OpenHaus Backend | ||
Wants=network-online.target | ||
After=network-online.target | ||
|
||
[Service] | ||
ExecStart=/usr/bin/node /opt/OpenHaus/backend/index.js | ||
WorkingDirectory=/opt/OpenHaus/backend | ||
Restart=always | ||
RestartSec=10 | ||
Environment=NODE_ENV=production | ||
Environment=VAULT_MASTER_PASSWORD=Pa$$w0rd | ||
Environment=USERS_JWT_SECRET=Pa$$w0rd | ||
Environment=UUID=00000000-0000-0000-0000-000000000000 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class MDNS { | ||
|
||
constructor(obj) { | ||
|
||
Object.assign(this, obj); | ||
this._id = String(obj._id); | ||
|
||
Object.defineProperty(this, "_matches", { | ||
value: [], | ||
writable: false, | ||
configurable: false, | ||
enumerable: false | ||
}); | ||
|
||
} | ||
|
||
match(cb) { | ||
this._matches.push(cb); | ||
} | ||
|
||
} | ||
|
||
module.exports = MDNS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const mongodb = require("mongodb"); | ||
const Joi = require("joi"); | ||
|
||
//const logger = require("../../system/logger").create("rooms"); | ||
//const COMMON_COMPONENT = require("../../system/component/common.js"); | ||
const COMPONENT = require("../../system/component/class.component.js"); | ||
|
||
const MDNS = require("./class.mdns.js"); | ||
|
||
const messageHandler = require("./message-handler.js"); | ||
|
||
/** | ||
* @description | ||
* Listen for mdns message and sends query requests.<br /> | ||
* This requires the "connector". | ||
* | ||
* The emitted message events is the parsed data received on the underlaying udp socket. | ||
* | ||
* @class C_MDNS | ||
* @extends COMPONENT system/component/class.component.js | ||
* | ||
* @emits message Received message on udp socket; Arguments: [0]=parsed dns packet, [1]=raw udp message | ||
* | ||
* @link router.api.mdns.js routes/router.api.mdns.js | ||
* @see https://en.wikipedia.org/wiki/Multicast_DNS | ||
* @see https://www.npmjs.com/package/dns-packet | ||
*/ | ||
class C_MDNS extends COMPONENT { | ||
|
||
constructor() { | ||
|
||
// inject logger, collection and schema object | ||
super("mdns", { | ||
_id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => { | ||
return String(new mongodb.ObjectId()); | ||
}), | ||
name: Joi.string().required(), | ||
type: Joi.string().valid("SRV", "PTR", "A", "AAAA").default("A"), | ||
timestamps: { | ||
announced: Joi.number().allow(null).default(null) | ||
} | ||
}, module); | ||
|
||
this.hooks.post("add", (data, next) => { | ||
next(null, new MDNS(data)); | ||
}); | ||
|
||
this.collection.createIndex({ | ||
name: 1, | ||
type: 1 | ||
}, { | ||
unique: true | ||
}); | ||
|
||
// handle incoming messages | ||
// triggers registerd callback for mdns items | ||
messageHandler(this); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
// create component instance | ||
const instance = module.exports = new C_MDNS(); | ||
|
||
|
||
// init component | ||
// set items/build cache | ||
instance.init((scope, ready) => { | ||
scope.collection.find({}).toArray((err, data) => { | ||
if (err) { | ||
|
||
// shit... | ||
ready(err); | ||
|
||
} else { | ||
|
||
data = data.map((obj) => { | ||
return new MDNS(obj); | ||
}); | ||
|
||
scope.items.push(...data); | ||
|
||
// init done | ||
ready(null); | ||
|
||
} | ||
}); | ||
}); |
Oops, something went wrong.