Reputation: 999
I am trying to send data of type ArrayBuffer in json to my server using socket.io like this:
socket.emit('record', {
name: myUsername + '.wav',
data: data //arraybuffer
});
On server side, when i receive 'record' event in socket, I get the data from JSON and save it in name file like this:
socket.on('record', function(message){
var fileWriter = new wav.FileWriter(message.name, {
channels: 1,
sampleRate: 48000,
bitDepth: 16
});
message.data.pipe(fileWriter);
});
I am using require('wav') & require('stream') package from npm. The problem is that my server crashes on message.data.pipe(fileWriter);
with this error:
TypeError: message.data.pipe is not a function
What am I doing wrong? Can't i send ArrayBuffer like this in socket.io?
Upvotes: 1
Views: 1839
Reputation: 1
data
is an ArrayBuffer
, not a ReadableStream
. Enqueue data
to be read by a ReadableStream
, passed to a WritableStream
or TransformStream
, for example using .pipeThrough()
, see Receiving data via stdin and storing as a variable/array.
Upvotes: 0