Handle browser-based WebSockets yielding Blob instances
This commit is contained in:
parent
ae5096fae2
commit
7267503337
|
@ -45,14 +45,24 @@ spawn named 'WebSocketFactory' {
|
||||||
ws = new _WebSocket(url, options);
|
ws = new _WebSocket(url, options);
|
||||||
|
|
||||||
ws.onerror = Dataspace.wrapExternal((e) => {
|
ws.onerror = Dataspace.wrapExternal((e) => {
|
||||||
console.error('WebSocket', id, url, e.message);
|
console.error('WebSocket', id, url, e);
|
||||||
disconnect();
|
disconnect();
|
||||||
sleep(1000, connect);
|
sleep(1000, connect);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.onopen = Dataspace.wrapExternal(() => { this.connected = true; });
|
ws.onopen = Dataspace.wrapExternal(() => { this.connected = true; });
|
||||||
ws.onclose = Dataspace.wrapExternal(() => { if (this.connected) { connect(); }});
|
ws.onclose = Dataspace.wrapExternal(() => { if (this.connected) { connect(); }});
|
||||||
ws.onmessage = Dataspace.wrapExternal((data) => { send DataIn(id, Bytes.fromIO(data.data)) });
|
ws.onmessage = Dataspace.wrapExternal((data) => {
|
||||||
|
if (typeof Blob !== 'undefined' && data.data instanceof Blob) {
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.addEventListener("loadend", Dataspace.wrapExternal(() => {
|
||||||
|
send DataIn(id, Bytes.from(reader.result));
|
||||||
|
}));
|
||||||
|
reader.readAsArrayBuffer(data.data);
|
||||||
|
} else {
|
||||||
|
send DataIn(id, Bytes.fromIO(data.data));
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
|
|
Loading…
Reference in New Issue