@openhps/core
Version:
Open Hybrid Positioning System - Core component
37 lines • 1.2 kB
JavaScript
import { RemoteNode } from '../RemoteNode';
import { Edge } from '../../graph/Edge';
import { SourceNode } from '../SourceNode';
/**
* Remote source node
*/
export class RemoteSourceNode extends SourceNode {
constructor(options) {
var _a;
super(options);
this.remoteNode = new ((_a = options.type) !== null && _a !== void 0 ? _a : RemoteNode)(options, this);
this.uid = `${this.uid}-source`;
this.once('build', this._onRemoteBuild.bind(this));
this.on('error', this._onDownstreamError.bind(this));
this.on('completed', this._onDownstreamCompleted.bind(this));
}
_onRemoteBuild(graphBuilder) {
// Add a remote node before this node
this.remoteNode.graph = this.graph;
graphBuilder.addNode(this.remoteNode);
graphBuilder.addEdge(new Edge(this.remoteNode, this));
return this.remoteNode.emitAsync('build', graphBuilder);
}
onPull() {
return new Promise((resolve, reject) => {
this.remoteNode.pull().then(() => {
resolve(undefined);
}).catch(reject);
});
}
_onDownstreamError(error) {
this.remoteNode.emit('error', error);
}
_onDownstreamCompleted(event) {
this.remoteNode.emit('completed', event);
}
}