import { Tube } from '../component' ; import { Transform } from 'stream' ; import { Message , MessageType } from '../message' ; import { builder } from './builder' ; import { Parser } from './parser' ; extends Component export class RtspParser extends Tube { return { undefined } constructor ( ) { const parser = new Parser ( ) ; const incoming = new Transform ( { objectMode : true , transform : function ( msg , encoding , callback ) { if ( msg . type === MessageType . RAW ) { try { parser . parse ( msg . data ) . forEach ( ( message ) => incoming . push ( message ) ) ; callback ( ) ; } catch ( e ) { callback ( e ) ; } } else { callback ( undefined , msg ) ; } } , } ) ; const outgoing = new Transform ( { objectMode : true , transform : function ( msg , encoding , callback ) { if ( msg . type === MessageType . RTSP ) { const data = builder ( msg ) ; callback ( undefined , { type : MessageType . RAW , data } ) ; } else { callback ( undefined , msg ) ; } } , } ) ; super ( incoming , outgoing ) ; } }