How to use the @node-wot/td-tools.Form function in @node-wot/td-tools

To help you get started, we’ve selected a few @node-wot/td-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse / thingweb.node-wot / packages / core / src / td-generator.ts View on Github external
console.debug(`generateTD() found ${Object.keys(boundThing.events).length} Events`);
  for (let eventName in boundThing.events) {
    let event = boundThing.events[eventName];

    // a form is generated for each address, supported protocol, and mediatype
    for (let address of Helpers.getAddresses()) {
      for (let type of ContentManager.getOfferedMediaTypes()) {
        for (let server of servient.getServers()) {
          // TODO get form directly from server, do not define URI paths here

          // if server is online !==-1 assign the href information
          if (server.getPort() !== -1 && server.scheme!=="mqtt") {
            let href: string = server.scheme + "://" + address + ":" + server.getPort() + "/" + thing.name;

            // depending on the resource pattern, uri is constructed
            let newForm = new TD.Form(href + "/events/" + eventName, type);
            if (server.scheme==="http") {
              newForm.subProtocol = "LongPoll";
            }

            event.forms.push(newForm);
            console.debug(`generateTD() assigns href '${href}' to Event '${eventName}'`);
          }
        }
      }
    }

    // in the case of mqtt the broker URI is used within the hrefs
    for (let server of servient.getServers()) {
      if(server.getPort() !== -1 && server.scheme=="mqtt") {
        for (let type of ContentManager.getOfferedMediaTypes()) {
github eclipse / thingweb.node-wot / packages / binding-mqtt / src / mqtt-broker-server.ts View on Github external
try {
              content = ContentSerdes.get().valueToContent(data, event.data);
            } catch(err) {
              console.warn(`HttpServer on port ${this.getPort()} cannot process data for Event '${eventName}: ${err.message}'`);
              // subscription.unsubscribe();
              thing.unsubscribeEvent(eventName);
              return;
            }
            // send event data
            console.log(`MqttBrokerServer at ${this.brokerURI} publishing to Event topic '${eventName}' `);
            this.broker.publish(topic, content.body);
          }
        );

        let href = this.brokerURI + topic;
        let form = new TD.Form(href, ContentSerdes.DEFAULT);
        form.op = ["subscribeevent", "unsubscribeevent"];
        event.forms.push(form);
        console.log(`MqttBrokerServer at ${this.brokerURI} assigns '${href}' to Event '${eventName}'`);
      }

      resolve();
    });
  }
github eclipse / thingweb.node-wot / packages / core / src / td-generator.ts View on Github external
}
      }
    }

    // in the case of mqtt the broker URI is used within the hrefs
    for (let server of servient.getServers()) {
      if(server.getPort() !== -1 && server.scheme=="mqtt") {
        for (let type of ContentManager.getOfferedMediaTypes()) {
        
          // cast since MqttBrokerServer offers a getAddress
          let href: string = server.scheme + "://" + server.getAddress() + ":" + server.getPort() + "/" + thing.name;
        
          // TODO: add mqtt based vocabularies (qos, retain) to the forms
        
          // depending on the resource pattern, uri is constructed
          event.forms.push(new TD.Form(href + "/events/" + eventName, type));
          console.debug(`generateTD() assigns href '${href}' to Event '${eventName}'`);
        }
      }
    } 

  }

  return boundThing;
}
github eclipse / thingweb.node-wot / packages / core / src / wot-impl.ts View on Github external
return new Promise((resolve, reject) => {
            let client = this.srv.getClientFor(Helpers.extractScheme(uri));
            console.info(`WoTImpl fetching TD from '${uri}' with ${client}`);
            client.readResource(new TD.Form(uri, ContentSerdes.TD))
                .then((content) => {
                    client.stop();

                    if (content.type !== ContentSerdes.TD &&
                        content.type !== ContentSerdes.JSON_LD ) {
                        console.warn(`WoTImpl received TD with media type '${content.type}' from ${uri}`);
                    }

                    let td = content.body.toString();

                    try {
                        JSON.parse(td);
                    } catch(err) {
                        console.warn(`WoTImpl fetched invalid JSON from '${uri}': ${err.message}`);
                    }

@node-wot/td-tools

W3C Web of Things (WoT) Thing Description parser, serializer, and other tools

EPL-2.0 OR W3C-20150513
Latest version published 22 days ago

Package Health Score

69 / 100
Full package analysis

Similar packages