-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebthingsio-gateway.js
69 lines (66 loc) · 2.23 KB
/
webthingsio-gateway.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const WebThingsEmitter = require('./webthingsio-webthings-emitter');
const semver = require('semver');
module.exports = function(RED) {
function WebthingsioGatewayNode(config) {
RED.nodes.createNode(this, config);
this.host = config.host;
this.port = +config.port;
this.https = config.https;
this.accessToken = config.accessToken;
this.skipValidation = config.skipValidation;
this.webthingsEmitter = new WebThingsEmitter(
RED,
this,
this.host,
this.port,
this.accessToken,
this.https,
this.skipValidation,
RED.settings.webthingsioGatewayReconnectInterval || 5,
);
this.on('close', () => {
this.webthingsEmitter.disconnect();
});
}
RED.nodes.registerType(
'webthingsio-gateway',
WebthingsioGatewayNode,
{
settings: {
webthingsioGatewayReconnectInterval: {
value: 5,
exportable: false,
},
webthingsioGatewayShorterLabels: {
value: false,
exportable: true,
},
webthingsioGatewayLimitInputLen: {
value: 15,
exportable: true,
},
},
},
);
const redversion = RED.version();
const version = redversion.substr(0, redversion.indexOf('-')) || redversion;
if (!semver.satisfies(version, '>=1.3.0')) {
// eslint-disable-next-line max-len
this.gateway.log(this.RED._('webthingsio-gateway.manuallyAddingClientCore'));
RED.httpAdmin.get(
// eslint-disable-next-line max-len
'/resources/node-red-contrib-webthingsio/webthingsio-client-core.js',
function(req, res) {
const options = {
root: __dirname,
dotfiles: 'deny',
};
res.set(
'Cache-Control',
'public, max-age=31557600, s-maxage=31557600',
);
res.sendFile('webthingsio-client-core.js', options);
},
);
}
};