diff --git a/node-red-node-wot/package-lock.json b/node-red-node-wot/package-lock.json
index e434216..a9bf06f 100644
--- a/node-red-node-wot/package-lock.json
+++ b/node-red-node-wot/package-lock.json
@@ -15,7 +15,8 @@
"@node-wot/binding-mqtt": "0.8.14",
"@node-wot/binding-opcua": "0.8.14",
"@node-wot/binding-websockets": "0.8.14",
- "@node-wot/core": "0.8.14"
+ "@node-wot/core": "0.8.14",
+ "@thingweb/td-utils": "^1.0.0"
},
"devDependencies": {
"@types/chai": "^4.3.12",
@@ -1294,6 +1295,11 @@
"node": ">=14.16"
}
},
+ "node_modules/@thingweb/td-utils": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@thingweb/td-utils/-/td-utils-1.0.0.tgz",
+ "integrity": "sha512-6TJ+2NUDicP1sXvWqorchj+F1Cc/zvCFJHtgIR8p5wI78jNSb0ZQHmpC2/bfZK2AkuE+6dgrzEcJcWNbVcB3sQ=="
+ },
"node_modules/@tsconfig/node10": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
diff --git a/node-red-node-wot/package.json b/node-red-node-wot/package.json
index 22ce891..1a6548d 100644
--- a/node-red-node-wot/package.json
+++ b/node-red-node-wot/package.json
@@ -43,7 +43,7 @@
"build": "npm run copy:src2dist && tsc && npm run build:plugin",
"copy:src2dist": "node -e \"require('fs-extra').copySync('./src', './dist')\"",
"build:plugin": "npm run copy:plugin-resources-src2resources && tsc --project ./tsconfig-for-plugin.json",
- "copy:plugin-resources-src2resources": "node -e \"require('fs-extra').copySync('./plugin-resources-src', './resources')\"",
+ "copy:plugin-resources-src2resources": "node -e \"require('fs-extra').copySync('./plugin-resources-src', './resources')\" && node -e \"require('fs-extra').copySync('./node_modules/@thingweb/td-utils/dist/web-bundle.min.js', './resources/@thingweb/td-utils/dist/web-bundle.min.js')\"",
"publish": "npm publish --access=public",
"publish:beta": "npm publish --access=public --tag=beta",
"test": "mocha --require ts-node/register --extension ts --exit"
@@ -55,7 +55,8 @@
"@node-wot/binding-mqtt": "0.8.14",
"@node-wot/binding-opcua": "0.8.14",
"@node-wot/binding-websockets": "0.8.14",
- "@node-wot/core": "0.8.14"
+ "@node-wot/core": "0.8.14",
+ "@thingweb/td-utils": "^1.0.0"
},
"devDependencies": {
"@types/chai": "^4.3.12",
diff --git a/node-red-node-wot/plugin-resources-src/node-wot-plugin-lib.ts b/node-red-node-wot/plugin-resources-src/node-wot-plugin-lib.ts
index 0ce0992..b2ed491 100644
--- a/node-red-node-wot/plugin-resources-src/node-wot-plugin-lib.ts
+++ b/node-red-node-wot/plugin-resources-src/node-wot-plugin-lib.ts
@@ -314,53 +314,17 @@ function generateId() {
return bytes.join("")
}
-function checkBinding(tdStr: string, binding: string) {
- let td
- try {
- td = JSON.parse(tdStr)
- } catch (err) {
- return false
- }
+const detectProtocolSchemes = (window as any).tdUtils?.detectProtocolSchemes;
- const affordances = ["properties", "actions", "events"]
+function checkBinding(tdStr: string, binding: string) {
// In case of OPC UA we look for opc.tcp in href not opcua
binding = binding === "opcua" ? "opc.tcp" : binding
// Also different for Modbus
binding = binding === "modbus" ? "modbus+tcp" : binding
- // Check base URL if present and then possibly affordances
- if (td["base"]) {
- let base = new URL(td["base"]).protocol
- if (base) {
- // remove trailing ':'
- base = base.slice(0, -1)
- const checkBase = base === binding || base === binding + "s"
- if (checkBase) return true
- }
- }
-
- for (const affordance of affordances) {
- if (td[affordance]) {
- // item is either a property or an action or an event
- for (const item of Object.values(td[affordance])) {
- if (!(item as any).forms) return false
- let checkForms = (item as any).forms.some((form) => {
- try {
- const parsed = new URL(form.href)
- if (parsed.protocol !== null) {
- // remove trailing ':'
- const scheme = parsed.protocol.slice(0, -1)
- return scheme === binding || scheme === binding + "s"
- }
- } catch (e) {
- return false
- }
- })
- if (checkForms) return true
- }
- }
- }
- return false
+ const bindings = Object.keys(detectProtocolSchemes(tdStr))
+
+ return bindings.some(b => b === binding || b === binding + 's')
}
const THING_COMMON_TEMP = `[
diff --git a/node-red-node-wot/plugin/node-wot-plugin.html b/node-red-node-wot/plugin/node-wot-plugin.html
index 9c7a5af..170c223 100644
--- a/node-red-node-wot/plugin/node-wot-plugin.html
+++ b/node-red-node-wot/plugin/node-wot-plugin.html
@@ -1,3 +1,5 @@
+
+