node-red-contrib-mobius-flow-base 2.5.91 → 3.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +16 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +16 -0
  3. package/.github/ISSUE_TEMPLATE/general.md +7 -0
  4. package/.github/workflows/build_publish.yml +80 -0
  5. package/README.md +4 -10
  6. package/dist/engine-api-calls.d.ts +18 -0
  7. package/dist/engine-api-calls.js +214 -0
  8. package/dist/engine-api-client.d.ts +7 -0
  9. package/dist/engine-api-client.js +92 -0
  10. package/dist/engine-websocket.d.ts +58 -0
  11. package/dist/engine-websocket.js +226 -0
  12. package/dist/node-red-ui-funcs.js +180 -0
  13. package/dist/nodes/common/mobsearch.js +576 -0
  14. package/dist/nodes/mobius-clear-resource.html +22 -3
  15. package/dist/nodes/mobius-clear-resource.js +17 -12
  16. package/dist/nodes/mobius-connection.html +30 -8
  17. package/dist/nodes/mobius-connection.js +194 -85
  18. package/dist/nodes/mobius-discover-object-list.html +185 -126
  19. package/dist/nodes/mobius-discover-object-list.js +24 -5
  20. package/dist/nodes/mobius-discover.js +7 -7
  21. package/dist/nodes/mobius-filter-by-rid-value.html +57 -41
  22. package/dist/nodes/mobius-filter-by-rid-value.js +38 -31
  23. package/dist/nodes/mobius-flow-inject.html +32 -2
  24. package/dist/nodes/mobius-get-multi-object.html +39 -5
  25. package/dist/nodes/mobius-get-multi-resource.html +36 -4
  26. package/dist/nodes/mobius-get-multi-resource.js +13 -12
  27. package/dist/nodes/mobius-get-object.html +25 -3
  28. package/dist/nodes/mobius-get-object.js +12 -9
  29. package/dist/nodes/mobius-get-resource.html +26 -3
  30. package/dist/nodes/mobius-get-resource.js +17 -12
  31. package/dist/nodes/mobius-object-cov.html +27 -3
  32. package/dist/nodes/mobius-object-cov.js +9 -6
  33. package/dist/nodes/mobius-resource-cov.html +23 -3
  34. package/dist/nodes/mobius-resource-cov.js +5 -5
  35. package/dist/nodes/mobius-set-multi-resource.html +24 -3
  36. package/dist/nodes/mobius-set-multi-resource.js +9 -11
  37. package/dist/nodes/mobius-set-resource.html +24 -3
  38. package/package.json +13 -7
  39. package/dist/nodes/node-red-ui-discover-devices.js +0 -103
@@ -26,28 +26,50 @@ POSSIBILITY OF SUCH DAMAGE.
26
26
 
27
27
  <script type="text/x-red" data-template-name="mobius connection">
28
28
  <div class="form-row">
29
- <label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
29
+ <div style="white-space: nowrap; display: inline-block;"><label for="node-config-input-host" style="width: 100px;" ><i class="fa fa-globe"></i> Host <span id="hostLabel" style="color: grey;">?</span></label></div>
30
30
  <input class="input-append-left" type="text" id="node-config-input-host" placeholder="e.g. localhost" style="width: 40%;" >
31
31
  <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
32
32
  <input type="text" id="node-config-input-port" placeholder="1890" style="width:50px">
33
33
  </div>
34
34
  <div class="form-row">
35
- <label for="node-config-input-psk"><i class="fa fa-key"></i> PSK</label>
36
- <input type="text" id="node-config-input-psk" placeholder="Pre-shared key">
35
+ <label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
36
+ <input class="input-append-left" type="text" id="node-config-input-username" style="width: 40%;" >
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-config-input-password"><i class="fa fa-key"></i> Password</label>
40
+ <input class="input-append-left" type="text" id="node-config-input-password" style="width: 40%;" >
41
+ </div>
42
+ <div class="form-row">
43
+ <label for="node-config-input-secure" style="width: 100px;"> Use SSL/TLS</label>
44
+ <input type="checkbox" id="node-config-input-secure" style="display: inline-block; width: auto; vertical-align: top;">
45
+
37
46
  </div>
38
47
  </script>
39
48
 
40
49
  <script type="text/javascript">
50
+ hostLabel = 'test';
41
51
  RED.nodes.registerType('mobius connection', {
42
52
  category: 'config',
43
53
  defaults: {
44
- host: {required: true, value: 'localhost'},
45
- port: {required: true, value: 1890, validate: RED.validators.number()},
46
- psk: {required: true}
54
+ host: { required: true, value: 'localhost' },
55
+ port: { required: true, value: 8443, validate: RED.validators.number() },
56
+ username: { required: true, value: 'admin' },
57
+ password: { required: true, value: 'adm123' },
58
+ secure: { required: true, value: true },
47
59
  },
48
- label: function() {
60
+ label: function () {
49
61
  return `${this.host}:${this.port}`;
50
- }
62
+ },
63
+ oneditprepare: function () {
64
+ $('#node-config-input-secure').change(function () {
65
+ let secure = $('#node-config-input-secure').is(':checked');
66
+ if (secure) {
67
+ document.getElementById('hostLabel').innerHTML = 'https://';
68
+ } else {
69
+ document.getElementById('hostLabel').innerHTML = 'http://';
70
+ }
71
+ });
72
+ },
51
73
  });
52
74
  </script>
53
75
 
@@ -27,8 +27,12 @@
27
27
  'use strict';
28
28
 
29
29
  var _ = require('lodash');
30
- var tcpAPI = require('@ia/mobius-tcpip-service-api');
31
- var uiDeviceDiscovery = require('./node-red-ui-discover-devices');
30
+ var uiFuncs = require('../node-red-ui-funcs');
31
+
32
+ const webSocket = require('../engine-websocket');
33
+ const apiCalls = require('../engine-api-calls');
34
+ const webSocketCalls = require('../engine-websocket');
35
+ const { getApiClient, setLoggedIn } = require('../engine-api-client');
32
36
 
33
37
  module.exports = function (RED) {
34
38
  /**
@@ -62,18 +66,25 @@ module.exports = function (RED) {
62
66
  RED.nodes.createNode(this, n);
63
67
  this.host = n.host;
64
68
  this.port = n.port;
65
- this.psk = n.psk;
66
- this.service = new tcpAPI.TCPIPServiceAPI(n.host, n.port, n.psk);
67
- this.service.srvcAPI.removeAllListeners('cov');
68
- this.service.srvcAPI.removeAllListeners('obcov');
69
- this.service.srvcAPI.removeAllListeners('bcmd');
70
- this.service.srvcAPI.on('cov', (response) => {
69
+ this.username = n.username;
70
+ this.password = n.password;
71
+ this.secure = n.secure;
72
+ this.apiClient = getApiClient(
73
+ this.secure ? 'https' : 'http',
74
+ this.host,
75
+ this.port,
76
+ this.username,
77
+ this.password
78
+ );
79
+ // webSocket.connectToWebSocket();
80
+ webSocket.clearAllCallbacks();
81
+ webSocket.registerCallback('resource-cov', (response) => {
71
82
  this.handleCOVEvents(response);
72
83
  });
73
- this.service.srvcAPI.on('obcov', (response) => {
84
+ webSocket.registerCallback('object-cov', (response) => {
74
85
  this.handleObjectCOVEvents(response);
75
86
  });
76
- this.service.srvcAPI.on('bcmd', (response) => {
87
+ webSocket.registerCallback('broadcast-command', (response) => {
77
88
  this.handleBCMDEvents(response);
78
89
  });
79
90
  var node = this;
@@ -85,11 +96,27 @@ module.exports = function (RED) {
85
96
  node.bcmdSubscriptions = new Map();
86
97
  node.connected = false;
87
98
  node.unsubscribeTimeout = 0;
99
+ node.hubId = null;
88
100
 
89
101
  // Connected to the mobius TCPIP spoke
90
102
  // Update the status indicators
91
- node.service.on('connected', () => {
103
+ webSocket.on('connected', () => {
92
104
  this.log(`Connected to ${n.host} : ${n.port}`);
105
+ apiCalls.getHubId(this.apiClient, (err, hubId) => {
106
+ if (err) {
107
+ node.error('Mobius error getting hub ID' + JSON.stringify(err));
108
+ } else {
109
+ node.hubId = hubId;
110
+ apiCalls.discover(this.apiClient, node.hubId, (err, response) => {
111
+ if (err) {
112
+ node.error('Mobius error discovering service list' + JSON.stringify(err));
113
+ } else {
114
+ node.serviceList = response.data;
115
+ node.hasStarted = true;
116
+ }
117
+ });
118
+ }
119
+ });
93
120
  node.connected = true;
94
121
  _.forEach(node.users, (user, id) => {
95
122
  if (node.users.hasOwnProperty(id)) {
@@ -102,30 +129,21 @@ module.exports = function (RED) {
102
129
  });
103
130
  // Subscribe to all COVs
104
131
  this.resourceSubscriptions.forEach((subs, key) => {
105
- node.service.srvcAPI.subscribeToCOV(key);
132
+ webSocketCalls.subscribeToResourceCOV(key);
106
133
  });
107
134
  // Subscribe to all object COVs
108
135
  node.objectSubscriptions.forEach((subs, key) => {
109
- node.service.srvcAPI.subscribeToObjectCOV(key);
136
+ webSocketCalls.subscribeToObjectCOV(key);
110
137
  });
111
138
  // Subscribe to all BCMDs
112
139
  node.bcmdSubscriptions.forEach((subs, key) => {
113
- node.service.srvcAPI.subscribeToBCMD(key);
114
- });
115
- // Discover all service IDs
116
- node.service.srvcAPI.discover(node.service.srvcAPI.status.hubId, (err, response) => {
117
- if (err) {
118
- node.error('Mobius error discovering service list' + JSON.stringify(err));
119
- } else {
120
- node.serviceList = response.value;
121
- node.hasStarted = true;
122
- }
140
+ webSocketCalls.subscribeToBCMD(key);
123
141
  });
124
142
  });
125
143
 
126
144
  // Disconnected from the mobius TCPIP spoke
127
145
  // Update the status indicators
128
- node.service.on('disconnected', () => {
146
+ webSocket.on('disconnected', () => {
129
147
  this.log(`Disconnected from ${n.host} : ${n.port}`);
130
148
  node.connected = false;
131
149
  for (var id in node.users) {
@@ -215,47 +233,44 @@ module.exports = function (RED) {
215
233
  */
216
234
  node.deregister = function (mobiusNode, done) {
217
235
  delete node.users[mobiusNode.id];
218
- if (node.service) {
219
- try {
220
- node.resourceSubscriptions.forEach((subs, key) => {
221
- subs.forEach((sub, index) => {
222
- if (mobiusNode.id === sub.node) {
223
- subs.splice(index, 1);
224
- }
225
- });
226
- if (subs.length === 0) {
227
- node.service.srvcAPI.unsubscribeToCOV(key);
228
- node.resourceSubscriptions.delete(key);
236
+ try {
237
+ node.resourceSubscriptions.forEach((subs, key) => {
238
+ subs.forEach((sub, index) => {
239
+ if (mobiusNode.id === sub.node) {
240
+ subs.splice(index, 1);
229
241
  }
230
242
  });
231
- node.objectSubscriptions.forEach((subs, key) => {
232
- subs.forEach((sub, index) => {
233
- if (mobiusNode.id === sub.node) {
234
- subs.splice(index, 1);
235
- }
236
- });
237
- if (subs.length === 0) {
238
- node.service.srvcAPI.unsubscribeToObjectCOV(key);
239
- node.objectSubscriptions.delete(key);
243
+ if (subs.length === 0) {
244
+ webSocketCalls.unsubscribeToResourceCOV(key);
245
+ node.resourceSubscriptions.delete(key);
246
+ }
247
+ });
248
+ node.objectSubscriptions.forEach((subs, key) => {
249
+ subs.forEach((sub, index) => {
250
+ if (mobiusNode.id === sub.node) {
251
+ subs.splice(index, 1);
240
252
  }
241
253
  });
242
- node.bcmdSubscriptions.forEach((subs, key) => {
243
- subs.forEach((sub, index) => {
244
- if (mobiusNode.id === sub.node) {
245
- subs.splice(index, 1);
246
- }
247
- });
248
- if (subs.length === 0) {
249
- node.service.srvcAPI.unsubscribeToBCMD(key);
250
- node.bcmdSubscriptions.delete(key);
254
+ if (subs.length === 0) {
255
+ webSocketCalls.unsubscribeToObjectCOV(key);
256
+ node.objectSubscriptions.delete(key);
257
+ }
258
+ });
259
+ node.bcmdSubscriptions.forEach((subs, key) => {
260
+ subs.forEach((sub, index) => {
261
+ if (mobiusNode.id === sub.node) {
262
+ subs.splice(index, 1);
251
263
  }
252
264
  });
253
- } catch (err) {
254
- console.log(`Failed to unsubscribe from event: ${err.message}`);
255
- }
256
- return done();
265
+ if (subs.length === 0) {
266
+ webSocketCalls.unsubscribeToBCMD(key);
267
+ node.bcmdSubscriptions.delete(key);
268
+ }
269
+ });
270
+ } catch (err) {
271
+ console.log(`Failed to unsubscribe from event: ${err.message}`);
257
272
  }
258
- done();
273
+ return done();
259
274
  };
260
275
 
261
276
  /**
@@ -273,16 +288,15 @@ module.exports = function (RED) {
273
288
  node.unsubscribeTimeout > 50
274
289
  ) {
275
290
  clearInterval(waitForCleanup);
276
- node.service.end();
277
- node.service.once('disconnected', () => {
278
- node.connected = false;
279
- done();
280
- });
291
+ webSocket.disconnectFromWebSocket();
292
+ setLoggedIn(false);
293
+ done();
281
294
  }
282
295
  node.unsubscribeTimeout++;
283
296
  }, 100);
284
297
  } else {
285
- node.service.end();
298
+ setLoggedIn(false);
299
+ webSocket.disconnectFromWebSocket();
286
300
  done();
287
301
  }
288
302
  });
@@ -296,7 +310,7 @@ module.exports = function (RED) {
296
310
  * the response message event
297
311
  */
298
312
  node.discover = function (uri, callback) {
299
- node.service.srvcAPI.discover(uri, callback);
313
+ apiCalls.discover(this.apiClient, uri, callback);
300
314
  };
301
315
 
302
316
  /**
@@ -307,7 +321,7 @@ module.exports = function (RED) {
307
321
  * @param {Function} callback - Callback when complete
308
322
  */
309
323
  node.writeResourceValue = function (uri, value, priority, callback) {
310
- node.service.srvcAPI.writeResourceValue(uri, value, priority, callback);
324
+ apiCalls.writeResource(this.apiClient, uri, value, priority, callback);
311
325
  };
312
326
 
313
327
  /**
@@ -320,7 +334,7 @@ module.exports = function (RED) {
320
334
  * the response message event
321
335
  */
322
336
  node.multiWriteResourceValue = function (uri, updates, callback) {
323
- node.service.srvcAPI.multiWriteResourceValue(uri, updates, callback);
337
+ apiCalls.writeMultiResource(this.apiClient, uri, updates, callback);
324
338
  };
325
339
 
326
340
  /**
@@ -330,7 +344,7 @@ module.exports = function (RED) {
330
344
  * @param {Function} callback - Callback when complete
331
345
  */
332
346
  node.clearResourcePriority = function (uri, priority, callback) {
333
- node.service.srvcAPI.clearResourcePriority(uri, priority, callback);
347
+ apiCalls.clearResource(this.apiClient, uri, priority, callback);
334
348
  };
335
349
 
336
350
  /**
@@ -339,7 +353,7 @@ module.exports = function (RED) {
339
353
  * @param {Function} callback - Callback when complete
340
354
  */
341
355
  node.readResource = function (uri, callback) {
342
- node.service.srvcAPI.readResource(uri, callback);
356
+ apiCalls.readResource(this.apiClient, uri, callback);
343
357
  };
344
358
 
345
359
  /**
@@ -348,7 +362,7 @@ module.exports = function (RED) {
348
362
  * @param {Function} callback - Callback when complete
349
363
  */
350
364
  node.readObject = function (uri, callback) {
351
- node.service.srvcAPI.readObject(uri, callback);
365
+ apiCalls.readObject(this.apiClient, uri, callback);
352
366
  };
353
367
 
354
368
  /**
@@ -361,7 +375,7 @@ module.exports = function (RED) {
361
375
  * @param {Function} callback - function(err, [object]) {}
362
376
  */
363
377
  node.filterObjectsByRIDValue = function (uri, pids, rid, limit, func, callback) {
364
- node.service.srvcAPI.filterObjectsByRIDValue(uri, pids, rid, limit, func, callback);
378
+ apiCalls.filterObjectsByRIDValue(this.apiClient, uri, pids, rid, limit, func, callback);
365
379
  };
366
380
 
367
381
  /**
@@ -376,7 +390,7 @@ module.exports = function (RED) {
376
390
  cb: callback,
377
391
  };
378
392
  if (!node.resourceSubscriptions.has(uri)) {
379
- node.service.srvcAPI.subscribeToCOV(uri);
393
+ webSocketCalls.subscribeToResourceCOV(uri);
380
394
  node.resourceSubscriptions.set(uri, [sub]);
381
395
  } else {
382
396
  // _.pullAllBy(node.resourceSubscriptions.get(uri), [{node: ref}], node);
@@ -397,7 +411,7 @@ module.exports = function (RED) {
397
411
  );
398
412
  }
399
413
  if (node.resourceSubscriptions.get(uri).length === 0) {
400
- node.service.srvcAPI.unsubscribeToCOV(uri);
414
+ webSocketCalls.unsubscribeToResourceCOV(uri);
401
415
  node.resourceSubscriptions.delete(uri);
402
416
  }
403
417
  };
@@ -414,7 +428,7 @@ module.exports = function (RED) {
414
428
  cb: callback,
415
429
  };
416
430
  if (!node.objectSubscriptions.has(uri)) {
417
- node.service.srvcAPI.subscribeToObjectCOV(uri);
431
+ webSocketCalls.subscribeToObjectCOV(uri);
418
432
  node.objectSubscriptions.set(uri, [sub]);
419
433
  } else {
420
434
  // _.pullAllBy(node.objectSubscriptions.get(uri), [{node: ref}], node);
@@ -435,7 +449,7 @@ module.exports = function (RED) {
435
449
  );
436
450
  }
437
451
  if (node.objectSubscriptions.get(uri).length === 0) {
438
- node.service.srvcAPI.unsubscribeToObjectCOV(uri);
452
+ webSocketCalls.unsubscribeToObjectCOV(uri);
439
453
  node.objectSubscriptions.delete(uri);
440
454
  }
441
455
  };
@@ -452,7 +466,7 @@ module.exports = function (RED) {
452
466
  cb: callback,
453
467
  };
454
468
  if (!node.bcmdSubscriptions.has(uri)) {
455
- node.service.srvcAPI.subscribeToBCMD(uri);
469
+ webSocketCalls.subscribeToBCMD(uri);
456
470
  node.bcmdSubscriptions.set(uri, [sub]);
457
471
  } else {
458
472
  node.bcmdSubscriptions.get(uri).push(sub);
@@ -472,7 +486,7 @@ module.exports = function (RED) {
472
486
  );
473
487
  }
474
488
  if (node.bcmdSubscriptions.get(uri).length === 0) {
475
- node.service.srvcAPI.unsubscribeToBCMD(uri);
489
+ webSocketCalls.unsubscribeToBCMD(uri);
476
490
  node.bcmdSubscriptions.delete(uri);
477
491
  }
478
492
  };
@@ -483,7 +497,7 @@ module.exports = function (RED) {
483
497
  * @param {Object} commandData - An object containing the command data
484
498
  */
485
499
  node.sendBroadcastCommand = function (cid, commandData) {
486
- node.service.srvcAPI.sendBroadcastCommand(cid, commandData);
500
+ apiCalls.sendBroadcastCommand(this.apiClient, cid, commandData);
487
501
  };
488
502
 
489
503
  /**
@@ -495,7 +509,7 @@ module.exports = function (RED) {
495
509
  * @param {Function} callback - Callback when complete
496
510
  */
497
511
  node.sendDirectCommand = function (uri, cid, commandData, timeout, callback) {
498
- node.service.srvcAPI.sendDirectCommand(uri, cid, commandData, timeout, callback);
512
+ apiCalls.sendDirectCommand(uri, cid, commandData, timeout, callback);
499
513
  };
500
514
 
501
515
  /**
@@ -505,7 +519,7 @@ module.exports = function (RED) {
505
519
  * @param {Function} callback - Callback when complete
506
520
  */
507
521
  node.getServiceConfig = function (hid, sid, callback) {
508
- node.service.srvcAPI.getServiceConfig(hid, sid, callback);
522
+ apiCalls.getServiceConfig(this.apiClient, `${hid}/${sid}`, callback);
509
523
  };
510
524
 
511
525
  /**
@@ -518,8 +532,17 @@ module.exports = function (RED) {
518
532
  * @param {Function} callback - Callback when complete
519
533
  */
520
534
  node.updateObjectInServiceConfig = function (hid, sid, pid, ins, config, callback) {
521
- node.service.srvcAPI.updateObjectInServiceConfig(hid, sid, pid, ins, config, callback);
535
+ apiCalls.updateObject(this.apiClient, `${hid}/${sid}/${pid}/${ins}`, config, callback);
522
536
  };
537
+
538
+ /**
539
+ * Get hub configuration
540
+ * @param {string} uri - The URI of the hub (hid)
541
+ * @param {Function} callback - Callback when complete
542
+ */
543
+ node.getNodeConfig = function (uri, callback) {
544
+ apiCalls.getNodeConfig(this.apiClient, uri, callback);
545
+ }
523
546
  }
524
547
 
525
548
  RED.nodes.registerType('mobius connection', MobiusConnectionNode);
@@ -541,11 +564,11 @@ module.exports = function (RED) {
541
564
  }
542
565
 
543
566
  let pid = req.query.pid;
544
- if (conn === null || !conn.service.connected) {
567
+ if (conn === null || !conn.connected) {
545
568
  RED.log.error('Discover objects failed - could not to connect to MOBiUS hub.');
546
569
  throw new Error('Discover objects failed - could not to connect to MOBiUS hub.');
547
570
  } else {
548
- uiDeviceDiscovery
571
+ uiFuncs
549
572
  .discoverDevicesByPID(RED, conn, hid, spids, pid)
550
573
  .then((devices) => {
551
574
  res.json(devices);
@@ -565,11 +588,11 @@ module.exports = function (RED) {
565
588
  let conn = RED.nodes.getNode(req.query.mobius);
566
589
  let hid = req.query.hid;
567
590
  let spid = req.query.spid;
568
- if (conn === null || !conn.service.connected) {
591
+ if (conn === null || !conn.connected) {
569
592
  RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
570
593
  throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
571
594
  } else {
572
- uiDeviceDiscovery
595
+ uiFuncs
573
596
  .discoverServicesBySPID(RED, conn, hid, spid)
574
597
  .then((services) => {
575
598
  res.json(services);
@@ -580,4 +603,90 @@ module.exports = function (RED) {
580
603
  }
581
604
  }
582
605
  );
606
+
607
+ // Register the endpoint for node-red mobius discovery in node-red node config pages
608
+ RED.httpAdmin.get('/mdiscover', RED.auth.needsPermission('serial.read'), function (req, res) {
609
+ let conn = RED.nodes.getNode(req.query.mobius);
610
+ let uri = req.query.uri;
611
+ if (conn === null || !conn.connected) {
612
+ RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
613
+ throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
614
+ } else {
615
+ uiFuncs
616
+ .discover(conn, uri)
617
+ .then((response) => {
618
+ res.json(response);
619
+ })
620
+ .catch((err) => {
621
+ throw err;
622
+ });
623
+ }
624
+ });
625
+
626
+ // Register the endpoint for node-red mobius discovery in node-red node config pages
627
+ RED.httpAdmin.get('/mgetservices', RED.auth.needsPermission('serial.read'), function (req, res) {
628
+ let conn = RED.nodes.getNode(req.query.mobius);
629
+ let hid = req.query.hid;
630
+ if (conn === null || !conn.connected) {
631
+ RED.log.error('Get services failed - could not to connect to MOBiUS hub.');
632
+ throw new Error('Get services failed - could not to connect to MOBiUS hub.');
633
+ } else {
634
+ uiFuncs
635
+ .getServiceList(conn, hid)
636
+ .then((response) => {
637
+ res.json(response);
638
+ })
639
+ .catch((err) => {
640
+ RED.log.warn(`Get services failed - ${err}`);
641
+ });
642
+ }
643
+ });
644
+
645
+ RED.httpAdmin.get('/mgetobjects', RED.auth.needsPermission('serial.read'), function (req, res) {
646
+ let conn = RED.nodes.getNode(req.query.mobius);
647
+ let hid = req.query.hid;
648
+ let sid = req.query.sid;
649
+ if (conn === null || !conn.connected) {
650
+ RED.log.error('Get objects failed - could not to connect to MOBiUS hub.');
651
+ throw new Error('Get objects failed - could not to connect to MOBiUS hub.');
652
+ } else {
653
+ uiFuncs
654
+ .getObjectList(conn, hid, sid)
655
+ .then((response) => {
656
+ res.json(response);
657
+ })
658
+ .catch((err) => {
659
+ RED.log.warn(`Get objects failed - ${err}`);
660
+ });
661
+ }
662
+ });
663
+
664
+ RED.httpAdmin.get('/mgethid', RED.auth.needsPermission('serial.read'), function (req, res) {
665
+ let conn = RED.nodes.getNode(req.query.mobius);
666
+ if (conn === null || !conn.connected) {
667
+ RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
668
+ throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
669
+ } else {
670
+ res.json(conn.hubId);
671
+ }
672
+ });
673
+
674
+ RED.httpAdmin.get('/mgetconnected', RED.auth.needsPermission('serial.read'), function (req, res) {
675
+ let conn = RED.nodes.getNode(req.query.mobius);
676
+ if (conn === null) {
677
+ RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
678
+ throw new Error('Get hid failed - could not to connect to MOBiUS hub.');
679
+ } else {
680
+ res.json(conn.connected);
681
+ }
682
+ });
683
+
684
+ RED.httpAdmin.get('/common/*', function (req, res) {
685
+ var options = {
686
+ root: __dirname + '/common/',
687
+ dotfiles: 'deny',
688
+ };
689
+ res.sendFile(req.params[0], options);
690
+ });
691
+
583
692
  };