How do I send binary data,e.g.mp3/mp4 data back to the frontend Javascript side?
I know there are two ways of doing it: utilizing the sandbox filesystem provided by NACL and get the url at the frontend; passing the data through the PostMessage()
using VarArrayBuffer
. It would be great if someone could give me a simple example of how to pass the binary data through PostMessage()
. There is a Pong example for NACl FileSystem API but I 'm kind of confused on how to retrieve the file location as url so that the frontend js could get it through the message.
Here is what I have done so far, using the second method of passing data through PostMessage()
and VarArrayBuffer
:
I successfully retrieved data from online mp4 file and stored it in a char vector
vector<char> outputBuffer
.Dumped the data into a new char buffer and create
VarArrayBuffer
to hold the data and pass it to the JS sidechar* binaryBuffer = new char[outputBuffer.size()]; int increment = 0; for (vector<char>::iterator it = outputBuffer.begin(); it != outputBuffer.end(); it++) { binaryBuffer[increment] = *it; } pp::VarArrayBuffer outBuffer(binaryBuffer); instance_->PostMessage(outBuffer);//instance_ is a NACL module instance
So, how should the JS side catch the array buffer? Is it through message.data
or something else? Thanks.