Sending Blob but receiveing (empty) ArrayBuffer

428 views
Skip to first unread message

Marco Chiappetta

unread,
Oct 6, 2013, 2:37:28 PM10/6/13
to pee...@googlegroups.com
Hi everybody! Here is the two snippets of code I used to send and receive a blob (generated by recorderjs, it's a wav stream):

// Sender
recorder.exportWAV(function(blob){
        console.log(blob); // Yeah, it's a blob and everything looks fine!
        conn.send(blob); // Connection correctly established, sending other types of objects work flawlessly
    });

// Receiver
conn.on('data', function(data){
                    console.log(data); // It says "ArrayBuffer {}"
                    playback.src = URL.createObjectURL(data); // Type error (of course...) - See the "Expansion" below
                });

Expansion:
  1. Uncaught TypeError: Type error client.html:27
    1. (anonymous function)client.html:27
    2. _reliable._reliable.onmessagepeer.min.js:1
    3. u._handleMessagepeer.min.js:1
    4. _dc.onmessage

Could you please help me figuring out what's wrong? If you need more information just ask. All the settings seem fine (serialization is "binary").

Thank you in advance.

Michelle Bu

unread,
Oct 8, 2013, 12:38:12 AM10/8/13
to Marco Chiappetta, peerjs
Hi Marco,

Can we see some code/a demo so we can try to replicate the error? And
just to be sure, you're using reliable:true in Chrome?
Michelle

Marco Chiappetta

unread,
Oct 11, 2013, 8:28:44 PM10/11/13
to pee...@googlegroups.com, Marco Chiappetta, miche...@berkeley.edu
Hi Michelle,

I solved it by taking a look at the "chat + file sharing" example on PeerJS website!

I simply added:

myData = new Blob(new Uint8Array(data), {type : "audio/wav"});

to the callback. I have no idea why this works but I'll try to figure it out after some hours of good sleep. :) Unless you want to give me a hint (I suppose you wrote that and the other examples). Anyway if I console.log data it's still "ArrayBuffer {}" but, evidently, it's not empty since I can correctly play the blob attaching its URL to an audio element's src attribute.

Thanks a lot for your help!

Marco Chiappetta

unread,
Oct 11, 2013, 8:29:41 PM10/11/13
to pee...@googlegroups.com, Marco Chiappetta, miche...@berkeley.edu
PS: I forgot, yes I specified {reliable: true} in the peer's configuration.

Cheers,
Reply all
Reply to author
Forward
0 new messages