Skip to content
Snippets Groups Projects
Commit e9c2af99 authored by Marin Karamihalev's avatar Marin Karamihalev
Browse files

added notifResp

parent 3525d87f
No related branches found
No related tags found
No related merge requests found
Pipeline #81149 passed
......@@ -7,6 +7,7 @@ import supported from "./supported";
import proto from "./proto";
import instances from "./instances";
import notify from "./notify";
import notifyResp from "./notifyResp";
export default {
GET: get,
......@@ -14,6 +15,7 @@ export default {
GET_SUPPORTED_DM: supported,
GET_SUPPORTED_PROTO: proto,
NOTIFY: notify,
NOTIFY_RESP: notifyResp,
ADD: add,
DELETE: del,
OPERATE: operate,
......
......@@ -10,7 +10,9 @@ const decode: DecodeFn = (msg) => {
const parent = util.searchParent(msg, "subscriptionId");
if (parent) {
const id = parent.subscriptionId;
const relField = Object.keys(parent).find((k) => k !== "subscriptionId");
const relField = Object.keys(parent).find((k) =>
k !== "subscriptionId" && k !== "sendResp"
);
return id && relField
? [parseInfo(relField, msg), id, null]
: [null, id, null];
......
import { DecodeFn, EncodeFn } from "../../types";
import { uniq } from "../util";
const decode: DecodeFn = (msg) => [msg];
const encode: EncodeFn = ({ subscriptionId }) => ({
lookup: "Msg",
header: {
msgId: uniq("NOTIFY_RESP@"),
msgType: "NOTIFY_RESP",
lookup: "Header",
},
body: {
lookup: "Body",
request: {
lookup: "Request",
notifyResp: { subscriptionId },
},
},
});
export default {
decode,
encode,
};
......@@ -3,28 +3,38 @@ import { uniq } from "../util";
const subscriptionPath = "Device.LocalAgent.Subscription.";
const make: MakeFn = (call, on): SubscribeRecipe => async (opts, callback) => {
const id = "NOTIFY@" + (opts.id || uniq());
const refList = Array.isArray(opts.reference) ? opts.reference.join(",") : opts.reference
const make: MakeFn =
(call, on): SubscribeRecipe =>
async (opts, callback) => {
const id = "NOTIFY@" + (opts.id || uniq());
const refList = Array.isArray(opts.reference)
? opts.reference.join(",")
: opts.reference;
const newSubPath = await call("ADD", {
path: subscriptionPath,
value: {
Enable: true,
ID: id,
NotifType: opts.notif,
NotifRetry: 'retry' in opts ? opts.retry : true,
ReferenceList: refList,
Persistent: false,
},
});
const newSubPath = await call("ADD", {
path: subscriptionPath,
value: {
Enable: true,
ID: id,
NotifType: opts.notif,
NotifRetry: "retry" in opts ? opts.retry : true,
ReferenceList: refList,
Persistent: false,
},
});
const clear = on(id, callback);
return () => {
clear();
return call("DELETE", { paths: newSubPath })
}
};
const respond = opts?.forceNoResponse
? () => {}
: () => call("NOTIFY_RESP", { subscriptionId: id });
const clear = on(id, (...args) => {
respond();
callback(...args);
});
return () => {
clear();
return call("DELETE", { paths: newSubPath });
};
};
export default {
name: "subscribe",
......
......@@ -254,6 +254,7 @@ 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 }),
on,
...makeRecipes(call, on),
disconnect: () => client.end(),
......
......@@ -7,6 +7,7 @@ export type CommandType =
| "DELETE"
| "OPERATE"
| "NOTIFY"
| "NOTIFY_RESP"
| "GET_SUPPORTED_DM"
| "GET_INSTANCES"
| "GET_SUPPORTED_PROTO";
......@@ -238,7 +239,8 @@ export type PbRequestCommand =
| PbRequestCommandOperate
| PbRequestCommandSupport
| PbRequestCommandInstance
| PbRequestCommandSupportProto;
| PbRequestCommandSupportProto
| PbRequestCommandNotifyResp;
export interface SuportedCommandOpts {
firstLevelOnly?: boolean;
......@@ -258,6 +260,12 @@ export type InputRecord = {
| boolean;
} & { allowPartial?: boolean };
export type PbRequestCommandNotifyResp = {
notifyResp: {
subscriptionId: string;
};
};
export type PbRequestCommandSupportProto = {
getSupportedProtocol: {
controllerSupportedProtocolVersions: string;
......@@ -607,6 +615,7 @@ export interface SubscriptionOptions {
id?: string;
notif: NotifType;
retry?: boolean;
forceNoResponse?: boolean;
reference: string | string[];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment