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
Checking pipeline status
...@@ -7,6 +7,7 @@ import supported from "./supported"; ...@@ -7,6 +7,7 @@ import supported from "./supported";
import proto from "./proto"; import proto from "./proto";
import instances from "./instances"; import instances from "./instances";
import notify from "./notify"; import notify from "./notify";
import notifyResp from "./notifyResp";
export default { export default {
GET: get, GET: get,
...@@ -14,6 +15,7 @@ export default { ...@@ -14,6 +15,7 @@ export default {
GET_SUPPORTED_DM: supported, GET_SUPPORTED_DM: supported,
GET_SUPPORTED_PROTO: proto, GET_SUPPORTED_PROTO: proto,
NOTIFY: notify, NOTIFY: notify,
NOTIFY_RESP: notifyResp,
ADD: add, ADD: add,
DELETE: del, DELETE: del,
OPERATE: operate, OPERATE: operate,
......
...@@ -10,7 +10,9 @@ const decode: DecodeFn = (msg) => { ...@@ -10,7 +10,9 @@ const decode: DecodeFn = (msg) => {
const parent = util.searchParent(msg, "subscriptionId"); const parent = util.searchParent(msg, "subscriptionId");
if (parent) { if (parent) {
const id = parent.subscriptionId; 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 return id && relField
? [parseInfo(relField, msg), id, null] ? [parseInfo(relField, msg), id, null]
: [null, 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"; ...@@ -3,28 +3,38 @@ import { uniq } from "../util";
const subscriptionPath = "Device.LocalAgent.Subscription."; const subscriptionPath = "Device.LocalAgent.Subscription.";
const make: MakeFn = (call, on): SubscribeRecipe => async (opts, callback) => { const make: MakeFn =
const id = "NOTIFY@" + (opts.id || uniq()); (call, on): SubscribeRecipe =>
const refList = Array.isArray(opts.reference) ? opts.reference.join(",") : opts.reference 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", { const newSubPath = await call("ADD", {
path: subscriptionPath, path: subscriptionPath,
value: { value: {
Enable: true, Enable: true,
ID: id, ID: id,
NotifType: opts.notif, NotifType: opts.notif,
NotifRetry: 'retry' in opts ? opts.retry : true, NotifRetry: "retry" in opts ? opts.retry : true,
ReferenceList: refList, ReferenceList: refList,
Persistent: false, Persistent: false,
}, },
}); });
const clear = on(id, callback); const respond = opts?.forceNoResponse
return () => { ? () => {}
clear(); : () => call("NOTIFY_RESP", { subscriptionId: id });
return call("DELETE", { paths: newSubPath }) const clear = on(id, (...args) => {
} respond();
}; callback(...args);
});
return () => {
clear();
return call("DELETE", { paths: newSubPath });
};
};
export default { export default {
name: "subscribe", name: "subscribe",
......
...@@ -254,6 +254,7 @@ const buildConnect: BuildConnectionFn = ...@@ -254,6 +254,7 @@ const buildConnect: BuildConnectionFn =
supportedProto: (proto) => call("GET_SUPPORTED_PROTO", { proto }), supportedProto: (proto) => call("GET_SUPPORTED_PROTO", { proto }),
_operate: (path, id, resp, input, commandKey) => _operate: (path, id, resp, input, commandKey) =>
call("OPERATE", { path, input, id, resp, commandKey }), call("OPERATE", { path, input, id, resp, commandKey }),
_notifyResp: (subscriptionId) => call("NOTIFY_RESP", { subscriptionId }),
on, on,
...makeRecipes(call, on), ...makeRecipes(call, on),
disconnect: () => client.end(), disconnect: () => client.end(),
......
...@@ -7,6 +7,7 @@ export type CommandType = ...@@ -7,6 +7,7 @@ export type CommandType =
| "DELETE" | "DELETE"
| "OPERATE" | "OPERATE"
| "NOTIFY" | "NOTIFY"
| "NOTIFY_RESP"
| "GET_SUPPORTED_DM" | "GET_SUPPORTED_DM"
| "GET_INSTANCES" | "GET_INSTANCES"
| "GET_SUPPORTED_PROTO"; | "GET_SUPPORTED_PROTO";
...@@ -238,7 +239,8 @@ export type PbRequestCommand = ...@@ -238,7 +239,8 @@ export type PbRequestCommand =
| PbRequestCommandOperate | PbRequestCommandOperate
| PbRequestCommandSupport | PbRequestCommandSupport
| PbRequestCommandInstance | PbRequestCommandInstance
| PbRequestCommandSupportProto; | PbRequestCommandSupportProto
| PbRequestCommandNotifyResp;
export interface SuportedCommandOpts { export interface SuportedCommandOpts {
firstLevelOnly?: boolean; firstLevelOnly?: boolean;
...@@ -258,6 +260,12 @@ export type InputRecord = { ...@@ -258,6 +260,12 @@ export type InputRecord = {
| boolean; | boolean;
} & { allowPartial?: boolean }; } & { allowPartial?: boolean };
export type PbRequestCommandNotifyResp = {
notifyResp: {
subscriptionId: string;
};
};
export type PbRequestCommandSupportProto = { export type PbRequestCommandSupportProto = {
getSupportedProtocol: { getSupportedProtocol: {
controllerSupportedProtocolVersions: string; controllerSupportedProtocolVersions: string;
...@@ -607,6 +615,7 @@ export interface SubscriptionOptions { ...@@ -607,6 +615,7 @@ export interface SubscriptionOptions {
id?: string; id?: string;
notif: NotifType; notif: NotifType;
retry?: boolean; retry?: boolean;
forceNoResponse?: boolean;
reference: string | string[]; reference: string | string[];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment