From c3efc90c5e86002c2bdf6b57e9bd9d32cdb23c4a Mon Sep 17 00:00:00 2001 From: Marin Karamihalev <marin.karamihalev@iopsys.eu> Date: Wed, 12 Apr 2023 12:39:21 +0200 Subject: [PATCH] hopefully resolved msgId issue for notufyResp --- package.json | 2 +- src/commands/common/notifyResp.ts | 4 ++-- src/commands/recipes/subscribe.ts | 7 ++++--- src/configurations/build.ts | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e966f7a..940aa32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "usp-js", - "version": "0.3.9", + "version": "0.3.10", "description": "Helper library for easy usp communication using mqtt over tcp or ws.", "main": "node/index.js", "browser": "web/index.js", diff --git a/src/commands/common/notifyResp.ts b/src/commands/common/notifyResp.ts index f975a89..2f7bd06 100644 --- a/src/commands/common/notifyResp.ts +++ b/src/commands/common/notifyResp.ts @@ -3,10 +3,10 @@ import { uniq } from "../util"; const decode: DecodeFn = (msg) => [msg]; -const encode: EncodeFn = ({ subscriptionId }) => ({ +const encode: EncodeFn = ({ subscriptionId, msgId }) => ({ lookup: "Msg", header: { - msgId: subscriptionId || uniq("NOTIFY_RESP@"), + msgId: msgId || uniq("NOTIFY_RESP@"), msgType: "NOTIFY_RESP", lookup: "Header", }, diff --git a/src/commands/recipes/subscribe.ts b/src/commands/recipes/subscribe.ts index 7d4c67c..9635838 100644 --- a/src/commands/recipes/subscribe.ts +++ b/src/commands/recipes/subscribe.ts @@ -1,5 +1,5 @@ import { CallbackOptions, MakeFn, SubscribeRecipe } from "../../types"; -import { uniq } from "../util"; +import { search, uniq } from "../util"; const subscriptionPath = "Device.LocalAgent.Subscription."; @@ -25,9 +25,10 @@ const make: MakeFn = // from https://usp.technology/specification/07-index-messages.html#sec:responses-and-retry - const respond = () => call("NOTIFY_RESP", { subscriptionId: id }); + const respond = (msgId) => + call("NOTIFY_RESP", { subscriptionId: id, msgId }); const clear = on(id, (msg, fullMsg, opts) => { - opts?.sendResp && respond(); + opts?.sendResp && respond(search(fullMsg, "msgId")); callback(msg, fullMsg); }); return () => { diff --git a/src/configurations/build.ts b/src/configurations/build.ts index deb85fa..c6ffbb1 100644 --- a/src/configurations/build.ts +++ b/src/configurations/build.ts @@ -256,8 +256,8 @@ const buildConnect: BuildConnectionFn = supportedProto: (proto) => call("GET_SUPPORTED_PROTO", { proto }), _operate: (path, id, resp, input, commandKey) => call("OPERATE", { path, input, id, resp, commandKey }), - _notifyResp: (subscriptionId) => - call("NOTIFY_RESP", { subscriptionId }), + _notifyResp: (subscriptionId, msgId) => + call("NOTIFY_RESP", { subscriptionId, msgId }), on, ...makeRecipes(call, on), disconnect: () => client.end(), -- GitLab