I'm trying to stream a from the client side to a server side, to later stream the video back to another client.
The point is:
How can I get chunks of a video from client-side JavaScript (that can be sent to a server)?
using this code, for example:
var x = new XMLHttpRequest();
var url = location.href;
x.onreadystatechange = function(){
if(x.readyState == 200) {
console.log("done");
} else {
console.log("chunk",x.response); //this is null until readyState is 200 anyway
}
}
x.onprogress = e => {
console.log("EE",e.target.response); //also null if resposneType is arraybuffer
};
x.responseType="arraybuffer";
x.open("GET","http://localhost:88/videoplayback.mp4",true);
x.send("");
When I try to print the response before its finished loading (to get it by chunks) then its simply null; the arraybuffer only returns as the respnse when its finished loading.
If I take out the responsetype and just leave it as plain text, then indeed some unicode-characters get printed to the screen for each readystatechange even before its finished, only an arraybuffer doesn't.
So: is this the best way to stream a video from the client to server, and if so, how can I actually do it? and if not, what's a better way?