GUACAMOLE-377: Use ImageDecoder to decode images while they are being received (if possible).

This commit is contained in:
Michael Jumper committed 2025-02-06 17:00:39 -08:00
1 parent 1454a5deae
commit 1a57d41a1b
3 files changed
+116 -16

No files matched your search

@@ -76,4 +76,66 @@ Guacamole.InputStream = function(client, index) {
client.sendAck(guac_stream.index, message, code);
};
/**
* Creates a new ReadableStream that receives the data sent to this stream
* by the Guacamole server. This function may be invoked at most once per
* stream, and invoking this function will overwrite any installed event
* handlers on this stream.
*
* A ReadableStream is a JavaScript object defined by the "Streams"
* standard. It is supported by most browsers, but not necessarily all
* browsers. The caller should verify this support is present before
* invoking this function. The behavior of this function when the browser
* does not support ReadableStream is not defined.
*
* @see {@link https://streams.spec.whatwg.org/#rs-class}
*
* @returns {!ReadableStream}
* A new ReadableStream that receives the bytes sent along this stream
* by the Guacamole server.
*/
this.toReadableStream = function toReadableStream() {
return new ReadableStream({
type: 'bytes',
start: function startStream(controller) {
var reader = new Guacamole.ArrayBufferReader(guac_stream);
// Provide any received blocks of data to the ReadableStream
// controller, such that they will be read by whatever is
// consuming the ReadableStream
reader.ondata = function dataReceived(data) {
if (controller.byobRequest) {
var view = controller.byobRequest.view;
var length = Math.min(view.byteLength, data.byteLength);
var byobBlock = new Uint8Array(data, 0, length);
view.buffer.set(byobBlock);
controller.byobRequest.respond(length);
if (length < data.byteLength) {
controller.enqueue(data.slice(length));
}
}
else {
controller.enqueue(new Uint8Array(data));
}
};
// Notify the ReadableStream when the end of the stream is
// reached
reader.onend = function dataComplete() {
controller.close();
};
}
});
};
};