dslink

JavaScript / Typescript SDK for the DSA protocol.

Usage no npm install needed!

<script type="module">
  import dslink from 'https://cdn.skypack.dev/dslink';
</script>

README

sdk-dslink-ts

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.

Install

npm install dslink --save
or
yarn add dslink

Use Typescript

To compile with dslink sdk's typescript definition, make sure esModuleInterop flag is true in typescript compilerOptions.

Install DsLink on broker

You can zip a javascript dslink and install it on dglux-server.

A working example

Nodejs Example (responder)

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();

Browser Example (requester only)

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();