javascript - Accessing Bytes in BinaryJS -


i have implemented nodejs server, using binaryjs. @ moment, can stream audio several clients , store wav file in server. server code of how doing it:

  binaryserver.on('connection', function (client) {   var filewriter = new wav.filewriter('records/' + n + '.wav', {     channels: 1,     samplerate: 48000,     bitdepth: 16   });    client.on('stream', function (stream, meta) {     stream.pipe(filewriter);        stream.on('end', function () {            filewriter.end();     });    }); }); 

now, want go further. want store streams in memory, use in advantage. that, need able access bytes of stream (right?). how can achieve this? found nothing in binaryjs api. seems need implement buffer.

console.log(stream):

  { domain: null,   _events:    { close: [ [function], [function: onclose], [function: cleanup] ],      data: [function: ondata],      end: [ [function: onend], [function: cleanup] ],      error: [function: onerror] },   _maxlisteners: undefined,   id: 0,   _socket:    { _socket:       { _connecting: false,         _haderror: false,         _handle: [object],         _host: null,         _readablestate: [object],         readable: true,         domain: null,         _events: [object],         _maxlisteners: undefined,         _writablestate: [object],         writable: true,         allowhalfopen: true,         destroyed: false,         bytesread: 530,         _bytesdispatched: 129,         _pendingdata: null,         _pendingencoding: '',         server: [object],         _idletimeout: -1,         _idlenext: null,         _idleprev: null,         _idlestart: 20175228,         parser: null,         _paused: false,         read: [function],         _consuming: true },      bytesreceived: 10,      readystate: 1,      supports: { binary: true },      protocol: undefined,      protocolversion: 13,      upgradereq:       { _readablestate: [object],         readable: true,         domain: null,         _events: {},         _maxlisteners: undefined,         socket: [object],         connection: [object],         httpversionmajor: 1,         httpversionminor: 1,         httpversion: '1.1',         complete: true,         headers: [object],         rawheaders: [object],         trailers: {},         rawtrailers: [],         _pendings: [],         _pendingindex: 0,         upgrade: true,         url: '/',         method: 'get',         statuscode: null,         statusmessage: null,         client: [object],         _consuming: false,         _dumped: false,         parser: null },      _isserver: true,      _receiver:       { fragmentedbufferpool: [object],         unfragmentedbufferpool: [object],         state: [object],         overflow: [],         headerbuffer: <buffer 45 28 26 9b e8 9c ff 02 8e 91>,         expectoffset: 0,         expectbuffer: <buffer 45 28>,         expecthandler: [function],         currentmessage: [],         dead: false,         onerror: [function],         ontext: [function],         onbinary: [function],         onclose: [function],         onping: [function],         onpong: [function] },      _sender: { _socket: [object], firstfragment: true, _events: [object] },      _events:       { close: [object],         open: [function],         drain: [function],         error: [function],         message: [object] },      binarytype: 'arraybuffer' },   writable: true,   readable: true,   paused: false,   _closed: false,   _ended: false } 

the solution:

binaryserver.on('connection', function (client) {    var filewriter = new wav.filewriter('records/' + n + '.wav', {     channels: 1,     samplerate: 48000,     bitdepth: 16   });    //evento --> quando se inicia o stream    client.on('stream', function (stream, meta) {      stream.pipe(filewriter);     /****the solution*****/     stream.on('data', function(data){       console.log(data);//<---buffer type     })        /**********************/        stream.on('end', function () {            console.log("end stream");           filewriter.end();     });    }); }); 

thanks tip @bergi. makes me think in different way..


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -