UNPKG

@litert/televoke

Version:
75 lines 2.46 kB
"use strict"; /** * Copyright 2025 Angus.Fenying <fenying@litert.org> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.LwDFXTransporter = void 0; const Shared = require("../../shared"); const node_events_1 = require("node:events"); const PROPERTY_NAMES = ['remoteAddress', 'remotePort', 'localAddress', 'localPort']; class LwDFXTransporter extends node_events_1.EventEmitter { constructor(protocol, _conn) { super(); this.protocol = protocol; this._conn = _conn; this._conn .on('end', () => this.emit('end')) .on('finish', () => this.emit('finish')) .on('frame', (data) => this.emit('frame', data)) .on('error', (e) => this.emit('error', e)) .on('close', () => this.emit('close')); } destroy() { this._conn.destroy(); } getPropertyNames() { return PROPERTY_NAMES; } getAllProperties() { return { 'remoteAddress': this._conn.remoteAddress, 'remotePort': this._conn.remotePort, 'localAddress': this._conn.localAddress, 'localPort': this._conn.localPort, }; } getProperty(name) { switch (name) { case 'localPort': case 'localAddress': case 'remotePort': case 'remoteAddress': return this._conn[name]; default: return undefined; } } get writable() { return this._conn.connected; } write(frame) { if (!this._conn.writable) { throw new Shared.errors.network_error({ reason: 'conn_lost' }); } this._conn.write(frame); } end() { if (this._conn.writable) { this._conn.end(); } } } exports.LwDFXTransporter = LwDFXTransporter; //# sourceMappingURL=LwDFX.Transporter.js.map