{"version":3,"sources":["local-loopback-interface.ts"],"sourcesContent":["import { Runtime } from \"../../runtime/runtime.ts\";\nimport { LOCAL_ENDPOINT, Endpoint } from \"../../types/addressing.ts\";\nimport { CommunicationInterface, CommunicationInterfaceSocket, InterfaceDirection, InterfaceProperties } from \"../communication-interface.ts\";\n\nexport class LocalLoopbackInterfaceSocket extends CommunicationInterfaceSocket {\n\n    open() {}\n    close() {}\n\n    send(dxb: ArrayBuffer) {\n        Runtime.datexIn({\n            dxb,\n            socket: this\n        })\n        return true;\n    }\n\n    override async sendHello(_dxb:ArrayBuffer) {\n        // ignore\n    }\n    override async sendGoodbye(_dxb:ArrayBuffer) {\n        // ignore\n    }\n}\n\n/**\n * Loopback interface for sending and DATEX messages to the local endpoint\n */\nexport class LocalLoopbackInterface extends CommunicationInterface<LocalLoopbackInterfaceSocket> {\n    \n    public properties: InterfaceProperties = {\n        type: \"local\",\n        direction: InterfaceDirection.OUT,\n        latency: 0,\n        bandwidth: 1_000_000\n    }\n\n    #currentSocket?: LocalLoopbackInterfaceSocket\n\n    constructor() {\n        super();\n    }\n\n    connect() {\n        // default @@local socket (never removed)\n        this.createSocket(LOCAL_ENDPOINT);\n\n        Runtime.onEndpointChanged((endpoint) => {\n            if (endpoint === LOCAL_ENDPOINT) return;\n            // remove socket for previous endpoint\n            if (this.#currentSocket) this.removeSocket(this.#currentSocket)\n            // add new socket for endpoint\n            this.#currentSocket = this.createSocket(endpoint);\n        })\n\n        return true;\n    }\n    disconnect() {}\t\n\n    private createSocket(endpoint: Endpoint) {\n        const socket = new LocalLoopbackInterfaceSocket();\n        socket.endpoint = endpoint;\n        this.addSocket(socket)\n        return socket;\n    }\n\n    cloneSocket(_socket: LocalLoopbackInterfaceSocket): never {\n        throw new Error(\"LocalLoopbackInterface does not support cloning\")\n    }\n    \n}"],"names":["Runtime","LOCAL_ENDPOINT","CommunicationInterface","CommunicationInterfaceSocket","InterfaceDirection","LocalLoopbackInterfaceSocket","open","close","send","dxb","datexIn","socket","sendHello","_dxb","sendGoodbye","LocalLoopbackInterface","properties","type","direction","OUT","latency","bandwidth","constructor","connect","createSocket","onEndpointChanged","endpoint","removeSocket","disconnect","addSocket","cloneSocket","_socket","Error"],"mappings":"AAAA,SAASA,OAAO,QAAQ,2BAA2B;AACnD,SAASC,cAAc,QAAkB,4BAA4B;AACrE,SAASC,sBAAsB,EAAEC,4BAA4B,EAAEC,kBAAkB,QAA6B,gCAAgC;AAE9I,OAAO,MAAMC,qCAAqCF;IAE9CG,OAAO,CAAC;IACRC,QAAQ,CAAC;IAETC,KAAKC,GAAgB,EAAE;QAKnB,OAJAT,QAAQU,OAAO,CAAC;YACZD;YACAE,QAAQ,IAAI;QAChB,IACO,CAAA;IACX;IAEA,MAAeC,UAAUC,IAAgB,EAAE,CAE3C;IACA,MAAeC,YAAYD,IAAgB,EAAE,CAE7C;AACJ;AAKA,OAAO,MAAME,+BAA+Bb;IAEjCc,aAAkC;QACrCC,MAAM;QACNC,WAAWd,mBAAmBe,GAAG;QACjCC,SAAS;QACTC,WAAW;IACf,EAAC;IAED,CAAA,aAAc,CAA+B;IAE7CC,aAAc;QACV,KAAK;IACT;IAEAC,UAAU;QAYN,OAVA,IAAI,CAACC,YAAY,CAACvB,iBAElBD,QAAQyB,iBAAiB,CAAC,CAACC;YACnBA,aAAazB,mBAEb,IAAI,CAAC,CAAA,aAAc,IAAE,IAAI,CAAC0B,YAAY,CAAC,IAAI,CAAC,CAAA,aAAc,GAE9D,IAAI,CAAC,CAAA,aAAc,GAAG,IAAI,CAACH,YAAY,CAACE;QAC5C,IAEO,CAAA;IACX;IACAE,aAAa,CAAC;IAENJ,aAAaE,QAAkB,EAAE;QACrC,IAAMf,SAAS,IAAIN;QAGnB,OAFAM,OAAOe,QAAQ,GAAGA,UAClB,IAAI,CAACG,SAAS,CAAClB,SACRA;IACX;IAEAmB,YAAYC,OAAqC,EAAS;QACtD,MAAM,AAAIC,MAAM;IACpB;AAEJ","sourceRoot":"/lib/datex-core-js-legacy-0.3.15/network/communication-interfaces/","file":"local-loopback-interface.ts"}