35 lines
600 B
JavaScript
35 lines
600 B
JavaScript
bricks = window.bricks || {};
|
|
|
|
bricks.UpStreaming = class extends bricks.JsWidget {
|
|
/*
|
|
{
|
|
"url":
|
|
}
|
|
*/
|
|
constructor(opts){
|
|
super(opts);
|
|
}
|
|
async go(){
|
|
this.body = new ReadableStream(this);
|
|
this.headers = new Headers();
|
|
this.headers.append('Content-Type',
|
|
'application/octet-stream');
|
|
var resp = await fetch(this.url, {
|
|
method: 'POST',
|
|
headers: this.headers,
|
|
duplex: 'full',
|
|
body: this.body
|
|
});
|
|
return resp
|
|
}
|
|
send(data){
|
|
this.stream_ctlr.enqueue(data);
|
|
}
|
|
finish(){
|
|
this.stream_ctlr.close();
|
|
}
|
|
start(controller){
|
|
this.stream_ctlr = controller;
|
|
}
|
|
}
|