UNPKG

@foxglove/ros1

Version:

Standalone TypeScript implementation of the ROS 1 (Robot Operating System) protocol with a pluggable transport layer

65 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscription = void 0; const eventemitter3_1 = require("eventemitter3"); const PublisherLink_1 = require("./PublisherLink"); class Subscription extends eventemitter3_1.EventEmitter { constructor({ name, md5sum, dataType, tcpNoDelay }) { super(); this._publishers = new Map(); this.name = name; this.md5sum = md5sum; this.dataType = dataType; this.tcpNoDelay = tcpNoDelay; } close() { this.removeAllListeners(); for (const pub of this._publishers.values()) { pub.connection.close(); } this._publishers.clear(); } publishers() { return this._publishers; } addPublisher(connectionId, rosFollowerClient, connection) { const publisher = new PublisherLink_1.PublisherLink(connectionId, this, rosFollowerClient, connection); this._publishers.set(connectionId, publisher); connection.on("header", (header, def, reader) => this.emit("header", header, def, reader)); connection.on("message", (msg, data) => this.emit("message", msg, data, publisher)); connection.on("error", (err) => this.emit("error", err)); } removePublisher(connectionId) { this._publishers.get(connectionId)?.connection.close(); return this._publishers.delete(connectionId); } getInfo() { return Array.from(this._publishers.values()).map((pub) => { return [ pub.connectionId, pub.publisherXmlRpcUrl().toString(), "i", pub.connection.transportType(), this.name, 1, pub.connection.getTransportInfo(), ]; }); } getStats() { const pubStats = Array.from(this._publishers.values()).map((pub) => { const stats = pub.connection.stats(); return [pub.connectionId, stats.bytesReceived, stats.messagesReceived, stats.dropEstimate, 0]; }); return [this.name, pubStats]; } receivedBytes() { let bytes = 0; for (const pub of this._publishers.values()) { bytes += pub.connection.stats().bytesReceived; } return bytes; } } exports.Subscription = Subscription; //# sourceMappingURL=Subscription.js.map