Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoAP ClientFactory #741

Closed
danielpeintner opened this issue Apr 20, 2022 · 4 comments
Closed

CoAP ClientFactory #741

danielpeintner opened this issue Apr 20, 2022 · 4 comments
Labels
binding-coap Issues related to coap protocol binding

Comments

@danielpeintner
Copy link
Member

@relu91 @danielpeintner
I haven't really tested but I was exploring the COAP example in readme and saw there

servient.addClientFactory(new CoapClientFactory(null));

How is this legit if it passes null as CoapServer, which was working before but in v8 the field is not nullable anymore?

Originally posted by @fatadel in #721 (comment)

@danielpeintner
Copy link
Member Author

I did test an updated code with passing CoapServer (attached the sample) and I now see another issue?

@JKRhb do you know "why" getSocket() is not a function?

[binding-coap] CoapClientFactory creating client for 'coap'
Fetch error: TypeError: server.getSocket is not a function
    at new CoapClient (C:\Users\mchn4310\node_modules\@node-wot\binding-coap\dist\coap-client.js:41:65)
    at CoapClientFactory.getClient (C:\Users\mchn4310\node_modules\@node-wot\binding-coap\dist\coap-client-factory.js:14:16)
    at Servient.getClientFor (C:\Users\mchn4310\node_modules\@node-wot\core\dist\servient.js:198:53)
    at C:\Users\mchn4310\node_modules\@node-wot\core\dist\helpers.js:112:37
    at new Promise (<anonymous>)
    at Helpers.fetch (C:\Users\mchn4310\node_modules\@node-wot\core\dist\helpers.js:111:16)

@danielpeintner danielpeintner added the binding-coap Issues related to coap protocol binding label Apr 20, 2022
@JKRhb
Copy link
Member

JKRhb commented Apr 20, 2022

Hmm, I tried to reproduce the issue but didn't encounter any problems.

Passing the server like this works fine:

Servient = require("@node-wot/core").Servient;
CoapClientFactory = require("@node-wot/binding-coap").CoapClientFactory;
CoapServer = require("@node-wot/binding-coap").CoapServer;

Helpers = require("@node-wot/core").Helpers;

// create Servient and add CoAP binding
let servient = new Servient();
const server = new CoapServer();
servient.addServer(server);
servient.addClientFactory(new CoapClientFactory(server));

let wotHelper = new Helpers(servient);
wotHelper
    .fetch("coap://plugfest.thingweb.io:5683/testthing")
    .then(async (td) => {
        // using await for serial execution (note 'async' in then() of fetch())
        try {
            const WoT = await servient.start();
            const thing = await WoT.consume(td);

            // read property
            const read1 = await thing.readProperty("string");
            console.log("string value is: ", await read1.value());
        } catch (err) {
            console.error("Script error:", err);
        }
    })
    .catch((err) => {
        console.error("Fetch error:", err);
    });

Also, the server argument is in fact nullable at the moment? Or am I missing something? Edit: Just noticed that I was looking in the wrong place, in the client factory the server is in fact non-nullable which shouldn't be the case, I suppose.

@JKRhb
Copy link
Member

JKRhb commented Apr 20, 2022

I just found where the non-nullable server argument was introduced: 0b2510a

@JKRhb
Copy link
Member

JKRhb commented May 11, 2022

I think this issue should be fixed by now, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-coap Issues related to coap protocol binding
Projects
None yet
Development

No branches or pull requests

2 participants