Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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(); });
}