diff --git a/src/commands/index.ts b/src/commands/index.ts
index e6b3e4cf61b0b8025035386a0b75369b86b86be6..d39f435231394804cb24b6ef5f9ecb2102f9da74 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -56,11 +56,6 @@ const unkownErr = (
msg: Record<string, string>
): [string, string, Record<string, any>] => ["error", "", msg];
-export const parseIds = (msg: Record<string, any>): string[] => [
- search(msg, "msgId"),
- search(msg, "subscriptionId"),
-].filter(v => v !== undefined)
-
export const readMsg = (data: any): Record<string, any> => {
const record = rootRecord.lookupType("usp_record.Record");
const decodedRecord: any = record.decode(data);
diff --git a/src/index.ts b/src/index.ts
index d6ed60378801cf7df33cf979c4107dbcebb25c47..43903c0d885add4ac3033caa313520b93f52851e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,5 @@
import mqttAsync from "async-mqtt";
-import { decode, makeEncode, makeRecipes, parseIds, readMsg } from "./commands";
+import { decode, makeEncode, makeRecipes, readMsg } from "./commands";
import {
ConnectionOptions,
USP,
@@ -61,11 +61,11 @@ export default async function connect(
else call.resolve(message);
}
- const ids = parseIds(parsedMsg);
- ids.forEach(i => {
- const cbs = callbackRouter.get(i);
- cbs.forEach((cb) => { cb(parsedMsg) })
- })
+ const cbs = callbackRouter.get(id);
+ cbs.forEach((cb) => {
+ if (message) cb(message, parsedMsg)
+ else if(err) cb(err, parsedMsg)
+ })
});
client.on("error", (err) => {
diff --git a/src/types.ts b/src/types.ts
index b678b036901355c8c65f5be87898ebb28a640659..c22eaa21e224e39af73ccfef4e438a1959514f5e 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -311,7 +311,7 @@ export interface SubscriptionOptions {
reference: string | string[];
}
-export type SubscriptionCallback = (msg: Response) => void;
+export type SubscriptionCallback = (msg: Response, fullMsg?: Record<string, any>) => void;
export interface OperateOptions {
ID?: string;