diff --git a/lib/src/example_modules/httpInterfaceServer.ts b/lib/src/example_modules/httpInterfaceServer.ts index b47b7be..8b39538 100644 --- a/lib/src/example_modules/httpInterfaceServer.ts +++ b/lib/src/example_modules/httpInterfaceServer.ts @@ -2,7 +2,7 @@ import type { Express } from "express"; import express from "express"; import { jsonization, types } from "@aas-core-works/aas-core3.0rc02-typescript"; import AASInterfaceServer from "../server"; -import type { OnRequestCallback } from "../server"; +import type { OnRequestCallback, Request } from "types/requests"; import AASStore from "../aasStore"; type Config = { @@ -11,7 +11,8 @@ type Config = { } export default class HTTPInterfaceServer extends AASInterfaceServer { - public name: string = "HTTPInterfaceServer"; + protected name: string = "HTTPInterfaceServer"; + protected supportsSubscriptions: boolean = false; // TODO, longpolling? private app: Express = express(); private server: any = null; @@ -22,10 +23,9 @@ export default class HTTPInterfaceServer extends AASInterfaceServer { } public prepare(): void { - const aas = AASStore.getInstance().getAll()[0]; this.app.use(express.json()); this.app.get("/aas", (_, res) => { - res.json(jsonization.toJsonable(aas)); + res.json(jsonization.toJsonable(this.aas)); }); } @@ -40,10 +40,13 @@ export default class HTTPInterfaceServer extends AASInterfaceServer { } public notify(event: any): void { + this.observers.forEach(observer => { + // TODO + // Notify long pollers + }); } - - protected findElementByRequest(request: string): any | null { - throw new Error("Method not implemented."); + + protected findElementByRequest(request: Request) { + } - } \ No newline at end of file diff --git a/lib/src/example_modules/mqttConnector.ts b/lib/src/example_modules/mqttConnector.ts new file mode 100644 index 0000000..82598b7 --- /dev/null +++ b/lib/src/example_modules/mqttConnector.ts @@ -0,0 +1,55 @@ +import * as mqtt from "mqtt"; +import { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0rc02-typescript/dist/types/types"; +import InterfaceConnectionObject from "interfaceConnectionObject"; + +class MQTTConnector extends InterfaceConnectionObject { + protected name: string = "MQTT Connector"; + protected uriProtocol: string[] = ["mqtt", "mqtts"]; + protected connectionType: "ON_DEMAND" | "PERMANENT" = "PERMANENT"; + protected supportsSubscriptions: boolean = true; + + private client: mqtt.MqttClient|null = null; + + public connect(): boolean { + if (!this.client) this.client = mqtt.connect(this.config); + return this.client.connected; + } + + public disconnect(): void { + if (this.client) this.client.end(); + this.client = null; + } + + public readProperty(prop: Property): void { + throw new Error("Method not implemented."); + } + + public writeProperty(prop: Property, value: any): void { + throw new Error("Method not implemented."); + } + + public observeProperty(prop: Property, callback: (value: any) => void): boolean { + throw new Error("Method not implemented."); + } + + public callActionSync(action: Operation, args: OperationVariable[]) { + throw new Error("Method not implemented."); + } + + public callActionAsync(action: Operation, args: OperationVariable[]): Promise { + throw new Error("Method not implemented."); + } + + public readAsyncActionResponse(action: Operation): Promise { + throw new Error("Method not implemented."); + } + + public subscribeEvent(callback: (event: BasicEventElement) => void): boolean { + throw new Error("Method not implemented."); + } + + public unsubscribeEvent(): void { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file