Work on connector
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as mqtt from "mqtt";
|
||||
import { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0-typescript/dist/types/types";
|
||||
import type { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0-typescript/dist/types/types";
|
||||
import InterfaceConnectionObject from "interfaceConnectionObject";
|
||||
|
||||
class MQTTConnector extends InterfaceConnectionObject<mqtt.IClientOptions> {
|
||||
@@ -10,8 +10,15 @@ class MQTTConnector extends InterfaceConnectionObject<mqtt.IClientOptions> {
|
||||
|
||||
private client: mqtt.MqttClient|null = null;
|
||||
|
||||
private store: Record<string, any> = {};
|
||||
|
||||
public connect(): boolean {
|
||||
if (!this.client) this.client = mqtt.connect(this.config);
|
||||
if (!this.client) this.client = mqtt.connect(this.connectionParameter);
|
||||
this.client.on("message", (topic, message) => {
|
||||
// If json is expected you could parse it here
|
||||
this.store[topic] = message.toString("utf-8");
|
||||
});
|
||||
this.client.subscribe("#");
|
||||
return this.client.connected;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { types } from "@aas-core-works/aas-core3.0-typescript";
|
||||
import type { EndpointMetadata } from "types/aidConf";
|
||||
|
||||
type ConnectionType = "ON_DEMAND" | "PERMANENT";
|
||||
|
||||
@@ -10,11 +11,13 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
|
||||
protected abstract readonly connectionType: ConnectionType;
|
||||
protected abstract readonly supportsSubscriptions: boolean;
|
||||
|
||||
protected config: ConfigInterface;
|
||||
private onResponseCallback: OnResponseCallback;
|
||||
protected readonly connectionParameter: ConfigInterface;
|
||||
protected readonly endpointMetadata: EndpointMetadata;
|
||||
private readonly onResponseCallback: OnResponseCallback;
|
||||
|
||||
public constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) {
|
||||
this.config = config;
|
||||
public constructor(connectionParameter: ConfigInterface, endpointMetadata: EndpointMetadata, onResponseCallback: OnResponseCallback) {
|
||||
this.connectionParameter = connectionParameter;
|
||||
this.endpointMetadata = endpointMetadata;
|
||||
this.onResponseCallback = onResponseCallback;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user