Skip to content

Commit

Permalink
Allow "lite" announce
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteinLTU committed Jul 30, 2024
1 parent b105600 commit 778724e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/procedures/iotscape/iotscape-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ IoTScapeServices.updateOrCreateServiceInfo = function (
let service = IoTScapeDevices._services[name];
IoTScapeServices._serviceDefinitions[name] = definition;

if(!rinfo) {
if (!service) {
// Service not added yet
service = IoTScapeDevices._services[name] = {};
}

if (!rinfo) {
logger.log("Service " + name + " created without connection info");
return;
}
Expand All @@ -34,11 +39,6 @@ IoTScapeServices.updateOrCreateServiceInfo = function (
rinfo.port,
);

if (!service) {
// Service not added yet
service = IoTScapeDevices._services[name] = {};
}

service[id] = rinfo;
};

Expand Down
11 changes: 9 additions & 2 deletions src/procedures/iotscape/iotscape.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ IoTScape._send = function (service, id, command, caller) {
* @param {RemoteInfo} remote Remote host information
*/
IoTScape._createService = async function (definition, remote = null) {

let parsed = null;

// Handle buffer input
if (Buffer.isBuffer(definition)) {
definition = definition.toString();
}

if (typeof definition === "string") {
try {
Expand All @@ -194,9 +200,10 @@ IoTScape._createService = async function (definition, remote = null) {

const name = Object.keys(parsed)[0];
parsed = parsed[name];

// Verify service definition is in message
if (typeof (parsed.service) == "undefined") {
logger.log("Service definition not found in message");
return;
}

Expand Down Expand Up @@ -269,7 +276,7 @@ IoTScape._createService = async function (definition, remote = null) {
} else {
logger.log(`Service ${name} already exists and is up to date`);
}
IoTScapeServices.updateOrCreateServiceInfo(name, parsed, id, remote);
IoTScapeServices.updateOrCreateServiceInfo(name, service, id, remote);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/procedures/iotscape/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ router.post(
IoTScape._createService(req.body);
res.status(200).send("OK");
},
)
);

module.exports = router;

0 comments on commit 778724e

Please sign in to comment.