I am learning from google codelab example Getting started with the Web Serial API
The example is on glitch so I remixed the code and follow the instructions and copied and pasted these code
let decoder = new TextDecoderStream();
inputDone = port.readable.pipeTo(decoder.writable);
inputStream = decoder.readable;
reader = inputStream.getReader();
readLoop();
Then I got 'TextDecoderStream' is not defined.
If it's not supported you can make a poly fill https://developer.mozilla.org/en-US/docs/Web/API/TransformStream
const tds = {
start(){
this.decoder = new TextDecoder(this.encoding, this.options)
},
transform(chunk, controller) {
controller.enqueue(this.decoder.decode(chunk))
}
}
let _jstds_wm = new WeakMap(); /* info holder */
class TextDecoderStream extends TransformStream {
constructor(encoding = 'utf-8', {...options} = {}) {
let t = {...tds, encoding, options}
super(t)
_jstds_wm.set(this, t)
}
get encoding() {return _jstds_wm.get(this).decoder.encoding}
get fatal() {return _jstds_wm.get(this).decoder.fatal}
get ignoreBOM() {return _jstds_wm.get(this).decoder.ignoreBOM}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With