import { AddressInfo } from 'net' ; import IncomingMessage from './incoming_message' ; import { packetToMessage } from './helpers' ; import { CoapPacket } from '../models/models' ; export default class ObserveReadStream extends IncomingMessage { _lastId : number | undefined ; _lastTime : number ; _disableFiltering : boolean ; constructor ( packet , rsinfo , outSocket ) { super ( packet , rsinfo , outSocket , { objectMode : true } ) ; this . _lastId = undefined ; this . _lastTime = 0 ; this . _disableFiltering = false ; this . append ( packet , true ) ; } append ( packet , firstPacket ) { if ( ! this . readable ) { return ; } if ( ! firstPacket ) { packetToMessage ( this , packet ) ; } if ( typeof this . headers . Observe !== 'number' ) { return ; } if ( this . _lastId === undefined ) { this . _lastId = this . headers . Observe - 1 ; } const dseq = ( this . headers . Observe - this . _lastId ) & 0xffffff ; const dtime = Date . now ( ) - this . _lastTime ; if ( this . _disableFiltering || ( dseq > 0 && dseq < ( 1 << 23 ) ) || dtime > 128 * 1000 ) { this . _lastId = this . headers . Observe ; this . _lastTime = Date . now ( ) ; this . push ( packet . payload ) ; } } close ( eagerDeregister ? ) { this . push ( null ) ; this . emit ( 'close' ) ; if ( eagerDeregister === true ) { this . emit ( 'deregister' ) ; } } _read ( ) { } }