Source Node
A source node is a node that creates or wraps data into data frames. Examples on creating an active or passive source node can be found in the interactive notebook here.
Passive source node
A passive source node is a source that only returns a data frame when it is requested through a pull.
ts
import {SourceNode ,DataFrame ,DataObject ,PullOptions ,SourceNodeOptions } from '@openhps/core';export classMyPassiveSource <Out extendsDataFrame > extendsSourceNode <Out > {constructor(options ?:SourceNodeOptions ) {super();}onPull (options ?:PullOptions ):Promise <Out > {return newPromise ((resolve ,reject ) => {constobject = newDataObject ("mysensor");constframe = newDataFrame (object );resolve (frame asOut );});}}
Active source node
An active source node is a source that automatically creates new data frames (e.g. a sensor that generates information at a fixed interval).
ts
import {SourceNode ,DataFrame ,DataObject ,PullOptions ,SourceNodeOptions } from '@openhps/core';export classMyActiveSource <Out extendsDataFrame > extendsSourceNode <Out > {private_timer :NodeJS .Timeout =undefined ;constructor(options ?:SourceNodeOptions ) {super();this.once ('build', this._initSensor .bind (this));this.once ('destroy', this._destroySensor .bind (this));}private_initSensor (): void {this._timer =setInterval (() => {constobject = newDataObject ("mysensor");constframe = newDataFrame (object );this.push (frame asOut );}, 1000);}private_destroySensor (): void {clearInterval (this._timer );}onPull (options ?:PullOptions ):Promise <Out > {return newPromise ((resolve ,reject ) => {resolve (undefined );});}}