How to pass the data obtained by getUserMedia to a binary Stream?

0

I want to know how to obtain information from a MediaStream in the form of a binary string so that later I can send it via WebSocket to a server.

As far as I know, the information is stored in the form of Blob inside the memory and the only thing that I could obtain so far is a URL that gives to that information.

Create that there are possibilities using HTML video and canvas tags. But it seems to me an unnecessary waste of resources to create visualization elements that I do not want, since my only objective is to send the data.

    
asked by Federico Morán 03.03.2017 в 20:40
source

1 answer

0

When a MediaRecorder receives data in the stream, it triggers a BlobEvent which has the data received as Blob :

recorder.ondatavailable = e => data.push(e.data);

That you can then join to create a Blob that is the recreation of the resource sent by stream:

let video = new Blob(data, { type: 'video/webm' });
  

I want to know how to get the information from a MediaStream in the form of a binary string so that later I can send it via WebSocket to a server.

In fact, if you look at the signatures of the Websocket#send , this is overloaded to support three types of data:

  

Okay, I already know that, but I need it sent in binary form.

In that case, you could use the FileReader#readAsArrayBuffer method to convert the blob to binary buffer:

let raw; // contenido binario
let reader = new FileReader();
reader.onloadend = buffer => raw = buffer;
reader.readAsArrayBuffer(video);
    
answered by 03.03.2017 / 21:53
source