openthread / ot-commissioner

OpenThread Commissioner, a Thread commissioner for joining new Thread devices and managing Thread networks.
https://openthread.io/
BSD 3-Clause "New" or "Revised" License
47 stars 34 forks source link

JavaScript interface for commissioning #276

Open dakhnod opened 2 months ago

dakhnod commented 2 months ago

I am creating a nodeJS application that is supposed to help with device commissioning. From that application, I want to be able to interface with the device commissioning process.

Unfortunately, the commissioning-cli does not provide any realistic way of interfacing with JavaScript code.

The SWIG interface file doesn't work, since it has a strong dependency on Java. Also, SWIG cannot handle std::shared_ptr.

Some solutions I have in mind are:

Is there any clever Idea I am missing?

wgtdkp commented 2 months ago

The CLI isn't a stable API, so it may not be a good idea to depend on that if you are targeting productions.

I think it's simpler and less code to use the library directly rather than building a client-server mode with a CLI daemon. I would suggest

  1. first try https://www.swig.org/Doc4.2/SWIGDocumentation.html#Javascript to see if it can fulfill your requirements
  2. If there are problems with SWIG and can't be workaround, try writing a node.js addon for the commissioner? https://nodejs.org/api/addons.html

Also, SWIG cannot handle std::shared_ptr

Do you mean SWIG_javascript doesn't support translating std::shared_ptr? I think it's used in only two places in commissioner.hpp and you can ignore those methods and create replacements with node.js addon?