@machhub-dev/sdk-ts 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,5 +6,5 @@ export declare class Tag {
6
6
  constructor(httpService: HTTPService, mqttService: MQTTService | null);
7
7
  getAllTags(): Promise<string[]>;
8
8
  publish(topic: string, data: any): Promise<void>;
9
- subscribe(topic: string, callback: (data: any) => void): Promise<void>;
9
+ subscribe(topic: string, callback: (data: any, topic?: string) => void): Promise<void>;
10
10
  }
@@ -7,7 +7,7 @@ export declare class MQTTService {
7
7
  constructor(url: string);
8
8
  static getInstance(url?: string, developerKey?: string): Promise<MQTTService>;
9
9
  static resetInstance(): void;
10
- addTopicHandler(topic: string, handler: (message: unknown) => void): void;
10
+ addTopicHandler(topic: string, handler: (message: unknown, topic?: string) => void): void;
11
11
  clearTopics(): void;
12
12
  publish(topic: string, message: unknown): boolean;
13
13
  private attachMessageListener;
@@ -91,7 +91,7 @@ class MQTTService {
91
91
  for (const subscribedTopic of this.subscribedTopics) {
92
92
  if (this.matchesTopic(subscribedTopic.topic, topic)) {
93
93
  const parsedMessage = this.parseMessage(message, topic);
94
- subscribedTopic.handler(parsedMessage);
94
+ subscribedTopic.handler(parsedMessage, topic);
95
95
  break;
96
96
  }
97
97
  }
@@ -6,5 +6,5 @@ export declare class Tag {
6
6
  constructor(httpService: HTTPService, mqttService: MQTTService | null);
7
7
  getAllTags(): Promise<string[]>;
8
8
  publish(topic: string, data: any): Promise<void>;
9
- subscribe(topic: string, callback: (data: any) => void): Promise<void>;
9
+ subscribe(topic: string, callback: (data: any, topic?: string) => void): Promise<void>;
10
10
  }
@@ -7,7 +7,7 @@ export declare class MQTTService {
7
7
  constructor(url: string);
8
8
  static getInstance(url?: string, developerKey?: string): Promise<MQTTService>;
9
9
  static resetInstance(): void;
10
- addTopicHandler(topic: string, handler: (message: unknown) => void): void;
10
+ addTopicHandler(topic: string, handler: (message: unknown, topic?: string) => void): void;
11
11
  clearTopics(): void;
12
12
  publish(topic: string, message: unknown): boolean;
13
13
  private attachMessageListener;
@@ -85,7 +85,7 @@ export class MQTTService {
85
85
  for (const subscribedTopic of this.subscribedTopics) {
86
86
  if (this.matchesTopic(subscribedTopic.topic, topic)) {
87
87
  const parsedMessage = this.parseMessage(message, topic);
88
- subscribedTopic.handler(parsedMessage);
88
+ subscribedTopic.handler(parsedMessage, topic);
89
89
  break;
90
90
  }
91
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -21,7 +21,7 @@ export class Tag {
21
21
  this.mqttService.publish(topic, data);
22
22
  }
23
23
 
24
- async subscribe(topic: string, callback: (data: any) => void): Promise<void> {
24
+ async subscribe(topic: string, callback: (data: any, topic?: string) => void): Promise<void> {
25
25
  if (!this.mqttService) {
26
26
  throw new Error("MQTT service not connected");
27
27
  }
@@ -2,7 +2,7 @@ import mqtt from 'mqtt';
2
2
 
3
3
  interface SubscribedTopic {
4
4
  topic: string;
5
- handler: (message: unknown) => void;
5
+ handler: (message: unknown, topic?: string) => void;
6
6
  }
7
7
 
8
8
  export class MQTTService {
@@ -46,7 +46,7 @@ export class MQTTService {
46
46
  }
47
47
 
48
48
  // addTopicHandler Adds a topic and handler to the subscribed list
49
- public addTopicHandler(topic: string, handler: (message: unknown) => void): void {
49
+ public addTopicHandler(topic: string, handler: (message: unknown, topic?: string) => void): void {
50
50
  try {
51
51
  this.subscribedTopics.push({ topic, handler });
52
52
  if (topic == "") return;
@@ -103,7 +103,7 @@ export class MQTTService {
103
103
  for (const subscribedTopic of this.subscribedTopics) {
104
104
  if (this.matchesTopic(subscribedTopic.topic, topic)) {
105
105
  const parsedMessage = this.parseMessage(message, topic);
106
- subscribedTopic.handler(parsedMessage);
106
+ subscribedTopic.handler(parsedMessage, topic);
107
107
  break;
108
108
  }
109
109
  }