Closed jenlincode closed 4 years ago
I get the same type of error when I try to call:
thing.setPropertyReadHandler() on the client side. Let me know if there's a dependency I may be missing?
Also when I try to run the client script:
node packages/cli/dist/cli.js --clientonly examples/scripts/example-event-client.js
WoT-Servient using defaults as 'wot-servient.conf.json' does not exist
DefaultServient configured with
{
servient: { clientOnly: true, scriptAction: false },
http: { port: 8080, selfSigned: false },
coap: { port: 5683 }
}
DefaultServient started
WoTImpl producing new ExposedThing 'servient'
Servient generating ID for 'servient': 'urn:uuid:8996f0b5-dff7-457e-981c-7aa523fff101'
Servient reset ID 'urn:uuid:8996f0b5-dff7-457e-981c-7aa523fff101' with 'servient'
ExposedThing 'servient' setting action Handler for 'log'
ExposedThing 'servient' setting action Handler for 'shutdown'
ExposedThing 'servient' setting action Handler for 'runScript'
ExposedThing 'servient' setting read handler for 'things'
ExposedThing 'servient' exposing all Interactions and TD
Servient has no servers to expose Things
serializeTD() produced
{"title":"servient","description":"node-wot CLI Servient","properties":{"things":{"type":"object","description":"Get things","observable":false,"readOnly":true,"writeOnly":false}},"actions":{"log":{"description":"Enable logging","input":{"type":"string"},"output":{"type":"string"},"idempotent":false,"safe":false},"shutdown":{"description":"Stop servient","output":{"type":"string"},"idempotent":false,"safe":false},"runScript":{"description":"Run script","input":{"type":"string"},"output":{"type":"string"},"idempotent":false,"safe":false}},"@context":"https://www.w3.org/2019/wot/td/v1","@type":"Thing","security":["nosec_sc"],"id":"urn:uuid:8996f0b5-dff7-457e-981c-7aa523fff101","securityDefinitions":{"nosec_sc":{"scheme":"nosec"}}}
WoT-Servient loading 1 command line script
WoT-Servient reading script examples/scripts/example-event-client.js
WoT-Servient running script '/********************************************************************************'... (35 lines)
Servient caught error in privileged '/mnt/c/Users/jade/Documents/GovTech/thingweb.node-wot/examples/scripts/example-event-client.js' and halted with /mnt/c/Users/jade/Documents/GovTech/thingweb.node-wot/examples/scripts/example-event-client.js:16
WoT.fetch("http://localhost:8080/EventSource").then( async (td) => {
^
TypeError: WoT.fetch is not a function
at /mnt/c/Users/jade/Documents/GovTech/thingweb.node-wot/examples/scripts/example-event-client.js:16:5
at Script.runInContext (vm.js:131:20)
at DefaultServient.Servient.runPrivilegedScript (/mnt/c/Users/jade/Documents/GovTech/thingweb.node-wot/packages/core/dist/servient.js:153:20)
at /mnt/c/Users/jade/Documents/GovTech/thingweb.node-wot/packages/cli/dist/cli.js:85:38
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
There are two subproblems here:
addAction
, addProperty
etc. If you ever see an example that is outdated, you can refer to this to see a list of changes that need to happen.You would need to use WoTHelpers instead of WoT, remove anything like addAction, addProperty etc.
So for example-event.js, addAction should be replaced with setActionHandler()? Just curious, but can the action be dynamically defined in example-event.js without the action being set up in "actions" part?
And I presume for example-event-client.js, replacing WoT with WoTHelpers would make it work?
Thanks for explaining some methods should only be set up on the server side -- I feel like some of that needs to almost be highlighted in another color in the documentation, since in wall-of-text documentation, I admittedly tend to skip over fine details. 😅
And I presume for example-event-client.js, replacing WoT with WoTHelpers would make it work?
Yes :)
So for example-event.js, addAction should be replaced with setActionHandler()? Just curious, but can the action be dynamically defined in example-event.js without the action being set up in "actions" part?
You don't need to replace it with something, you can simply remove it. Before, we were adding each interaction with a method but now you just put a TD in the produce( )
method and it adds all the interactions you have put in the TD.
Thanks for all the support, Ege! Closing this issue now.
FYI: we are working on a PR to update all examples.
When I run:
node packages/cli/dist/cli.js examples/scripts/example-event.js
I get the error:
There's likely something obvious that I'm forgetting, as this is one of the default example files that's included with node-wot. Just curious what I may be missing.