JavaScript / Typescript SDK for the DSA protocol.
Version 2.0 of this sdk is re-written with typescript and is NOT backward compatible with the DSA javascript sdk 1.x.
npm install dslink --save
or
yarn add dslink
To compile with dslink sdk's typescript definition, make sure esModuleInterop
flag is true in typescript compilerOptions.
You can zip a javascript dslink and install it on dglux-server.
A sample dslink with a basic value node at the path /value
const {DSLink, RootNode, ValueNode} = require("dslink");
class MyValueNode extends ValueNode {
constructor(path, provider) {
super(path, provider, 'myvalue', 'number');
this._value = 123;
}
}
function main() {
let rootNode = new RootNode();
rootNode.createChild('value', MyValueNode);
let link = new DSLink('mydslink', {rootNode});
link.connect();
}
main();
const {DSLink} = require('dslink/js/web');
async function main() {
let link = new DSLink('ws://localhost:8080/ws', 'json');
link.connect();
let {requester} = link;
console.log(await requester.subscribeOnce('/sys/dataOutPerSecond'));
}
main();