How to use the node-coap-client.CoapClient.observe function in node-coap-client

To help you get started, we’ve selected a few node-coap-client 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 AlCalzone / node-tradfri-client / src / tradfri-client.ts View on Github external
public async observeResource(path: string, callback: (resp: CoapResponse) => void): Promise {

		path = normalizeResourcePath(path);

		// check if we are already observing this resource
		const observerUrl = `${this.requestBase}${path}`;
		if (this.observedPaths.indexOf(observerUrl) > -1) return false;

		// start observing
		this.observedPaths.push(observerUrl);
		await coap.observe(observerUrl, "get", callback);
		return true;
	}
github eclipse / thingweb.node-wot / packages / binding-coap / src / coaps-client.ts View on Github external
public subscribeResource(form: CoapForm, next: ((value: any) => void), error?: (error: any) => void, complete?: () => void): any {

    let requestUri = url.parse(form.href.replace(/$coaps/, "https"));
    coaps.setSecurityParams(requestUri.hostname, this.authorization );

    coaps.observe(
      form.href,
      "get",
      next
    )
    .then(() => { /* observing was successfully set up */})
    .catch((err: any) => { error(err); })

    return new Subscription(() => { coaps.stopObserving(form.href); complete(); });
  }