Skip to content

Commit

Permalink
fixup! chore(binding-coap): use ts strict checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Aug 10, 2023
1 parent 1fee2bd commit 4564b3f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export default class CoapServer implements ProtocolServer {
if (req.headers.Observe == null) {
this.handleReadProperty(property, req, contentType, thing, res, affordanceKey);
} else {
this.handleObserveProperty(req, thing, res, affordanceKey);
this.handleObserveProperty(property, req, contentType, thing, res, affordanceKey);
}
break;
case "PUT":
Expand Down Expand Up @@ -517,15 +517,25 @@ export default class CoapServer implements ProtocolServer {
}

private async handleObserveProperty(
property: PropertyElement,
req: IncomingMessage,
contentType: string,
thing: ExposedThing,
res: OutgoingMessage,
affordanceKey: string
) {
const interactionOptions = this.createInteractionOptions(
property.forms,
thing,
req,
contentType,
property.uriVariables
);

const listener = this.createContentListener(req, res, this.PROPERTY_DIR, affordanceKey);

try {
await thing.handleObserveProperty(affordanceKey, listener);
await thing.handleObserveProperty(affordanceKey, listener, interactionOptions);
} catch (error) {
warn(`${error}`);
}
Expand All @@ -536,10 +546,10 @@ export default class CoapServer implements ProtocolServer {
if (err) {
error(`CoapServer on port ${this.port} failed on observe with: ${err.message}`);
}
thing.handleUnobserveProperty(affordanceKey, listener);
thing.handleUnobserveProperty(affordanceKey, listener, interactionOptions);
});

setTimeout(() => thing.handleUnobserveProperty(affordanceKey, listener), 60 * 60 * 1000);
setTimeout(() => thing.handleUnobserveProperty(affordanceKey, listener, interactionOptions), 60 * 60 * 1000);
}

private createContentListener(
Expand Down

0 comments on commit 4564b3f

Please sign in to comment.