@danidoble/webserial 4.4.6 → 4.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/relay.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-CR94n4kR.cjs"),a=require("./relay-E3NCcSjS.cjs");class r extends n.Kernel{constructor({filters:t=null,config_port:e,no_device:s=1,socket:i=!1}={}){if(super({filters:t,config_port:e,no_device:s,socket:i}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],n.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);n.Devices.add(this)}serialMessage(t){t=this.fixHexArray(t);const e={code:t,name:null,description:null,request:null,no_code:0};t[0]==="a0"&&t[2]=="00"?(e.name="Relay turned off",e.description="The relay has been turned off successfully.",e.request=this.lastAction,e.no_code=101):t[0]==="a0"&&t[2]=="01"?(e.name="Relay turned on",e.description="The relay has been turned on successfully.",e.request=this.lastAction,e.no_code=102):(e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400),this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){return a.e.connection(t)}async turnOn(){const t=a.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=a.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await n.wait(e),await this.turnOff();return}await this.turnOff(),await n.wait(e),await this.turnOn()}}exports.Relay=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-DHq-6p9p.cjs"),a=require("./relay-BG7CetDU.cjs");class r extends n.Kernel{constructor({filters:t=null,config_port:e,no_device:s=1,socket:i=!1}={}){if(super({filters:t,config_port:e,no_device:s,socket:i}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],n.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);n.Devices.add(this)}serialMessage(t){t=this.fixHexArray(t);const e={code:t,name:null,description:null,request:null,no_code:0};t[0]==="a0"&&t[2]=="00"?(e.name="Relay turned off",e.description="The relay has been turned off successfully.",e.request=this.lastAction,e.no_code=101):t[0]==="a0"&&t[2]=="01"?(e.name="Relay turned on",e.description="The relay has been turned on successfully.",e.request=this.lastAction,e.no_code=102):(e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400),this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){return a.e.connection(t)}async turnOn(){const t=a.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=a.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await n.wait(e),await this.turnOff();return}await this.turnOff(),await n.wait(e),await this.turnOn()}}exports.Relay=r;
package/dist/relay.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as o, D as a, w as i } from "./kernel-BfYgLcpB.js";
2
- import { e as n } from "./relay-DP8PLsDP.js";
1
+ import { K as o, D as a, w as i } from "./kernel-BRG-vva2.js";
2
+ import { e as n } from "./relay-C71zVBZv.js";
3
3
  class f extends o {
4
4
  constructor({ filters: t = null, config_port: e, no_device: s = 1, socket: r = !1 } = {}) {
5
5
  if (super({ filters: t, config_port: e, no_device: s, socket: r }), this.__internal__.device.type = "relay", this.__internal__.auto_response = !1, this.__internal__.serial.auto_response = [2, 6, 221, 221, 240, 207, 3], a.getCustom(this.typeDevice, s))
@@ -57,6 +57,8 @@ export declare class PinPax extends Kernel {
57
57
  exit(): Promise<void>;
58
58
  init(): Promise<void>;
59
59
  login(): Promise<void>;
60
+ stop(): Promise<void>;
61
+ verifyNetwork(): Promise<void>;
60
62
  }
61
63
  export {};
62
64
  //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M;;IAChC,UAAU,EAAE,cAAc,CAgBxB;gBAEA,EACE,OAAc,EACd,WAOC,EACD,SAAa,EACb,wBAA4B,EAC5B,MAAc,GACf,GAAE,iBAaF;IAqCH,IAAI,UAAU,CAAC,UAAU,eAAA,EAExB;IACD,IAAI,UAAU,kBAEb;IAED,IAAI,aAAa,CAAC,aAAa,eAAA,EAE9B;IACD,IAAI,aAAa,kBAEhB;IAED,IAAI,MAAM,CAAC,MAAM,eAAA,EAEhB;IACD,IAAI,MAAM,kBAET;IAED,IAAI,MAAM,CAAC,MAAM,uBAAA,EAEhB;IACD,IAAI,MAAM,0BAET;IAEQ,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,GAAG,WAAW;IAyMlF,2BAA2B;IAIpC,UAAU;IAQK,cAAc,CAAC,IAAI,GAAE,GAAQ;IAWtC,cAAc;IA8CpB,0BAA0B;IAgDpB,QAAQ,CACZ,EACE,MAAU,EACV,SAAgB,GACjB,GAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAI3B;IAsDG,UAAU,CAAC,EAAE,KAAY,EAAE;;KAAK;IAkChC,IAAI;IAIJ,SAAS;IAIT,UAAU;IAIV,SAAS;IAIT,WAAW;IAKX,WAAW;IAKX,IAAI;IAKJ,MAAM,CAAC,EAAE,MAAU,EAAE,KAAY,EAAE,IAAW,EAAE;;;;KAAK;IAWrD,gBAAgB;IAIhB,sBAAsB;IAItB,IAAI;IAIJ,IAAI;IAIJ,KAAK;IAeL,IAAI;IAIJ,aAAa;CAGpB"}
@@ -21,7 +21,7 @@ function Q(n) {
21
21
  return n instanceof Uint8Array ? n : n instanceof ArrayBuffer ? new Uint8Array(n) : new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
22
22
  }
23
23
  let P;
24
- function pe(n, e) {
24
+ function de(n, e) {
25
25
  if (te && n.data instanceof Blob)
26
26
  return n.data.arrayBuffer().then(Q).then(e);
27
27
  if (se && (n.data instanceof ArrayBuffer || ne(n.data)))
@@ -62,7 +62,7 @@ const ye = (n) => {
62
62
  return ie(t, e);
63
63
  } else
64
64
  return { base64: !0, data: n };
65
- }, ie = (n, e) => e === "blob" ? n instanceof Blob ? n : new Blob([n]) : n instanceof ArrayBuffer ? n : n.buffer, re = "", be = (n, e) => {
65
+ }, ie = (n, e) => e === "blob" ? n instanceof Blob ? n : new Blob([n]) : n instanceof ArrayBuffer ? n : n.buffer, re = "", we = (n, e) => {
66
66
  const t = n.length, s = new Array(t);
67
67
  let i = 0;
68
68
  n.forEach((r, o) => {
@@ -70,7 +70,7 @@ const ye = (n) => {
70
70
  s[o] = l, ++i === t && e(s.join(re));
71
71
  });
72
72
  });
73
- }, we = (n, e) => {
73
+ }, be = (n, e) => {
74
74
  const t = n.split(re), s = [];
75
75
  for (let i = 0; i < t.length; i++) {
76
76
  const r = W(t[i], e);
@@ -82,7 +82,7 @@ const ye = (n) => {
82
82
  function ve() {
83
83
  return new TransformStream({
84
84
  transform(n, e) {
85
- pe(n, (t) => {
85
+ de(n, (t) => {
86
86
  const s = t.length;
87
87
  let i;
88
88
  if (s < 126)
@@ -204,13 +204,13 @@ u.prototype.listeners = function(n) {
204
204
  u.prototype.hasListeners = function(n) {
205
205
  return !!this.listeners(n).length;
206
206
  };
207
- const O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), p = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ce = "arraybuffer";
207
+ const O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), d = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ce = "arraybuffer";
208
208
  function ae(n, ...e) {
209
209
  return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
210
210
  }
211
- const Te = p.setTimeout, Ae = p.clearTimeout;
211
+ const Te = d.setTimeout, Ae = d.clearTimeout;
212
212
  function L(n, e) {
213
- e.useNativeTimers ? (n.setTimeoutFn = Te.bind(p), n.clearTimeoutFn = Ae.bind(p)) : (n.setTimeoutFn = p.setTimeout.bind(p), n.clearTimeoutFn = p.clearTimeout.bind(p));
213
+ e.useNativeTimers ? (n.setTimeoutFn = Te.bind(d), n.clearTimeoutFn = Ae.bind(d)) : (n.setTimeoutFn = d.setTimeout.bind(d), n.clearTimeoutFn = d.clearTimeout.bind(d));
214
214
  }
215
215
  const Se = 1.33;
216
216
  function xe(n) {
@@ -398,7 +398,7 @@ class Pe extends K {
398
398
  return this.onClose({ description: "transport closed by the server" }), !1;
399
399
  this.onPacket(s);
400
400
  };
401
- we(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
401
+ be(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
402
402
  }
403
403
  /**
404
404
  * For polling, send a close packet.
@@ -418,7 +418,7 @@ class Pe extends K {
418
418
  * @protected
419
419
  */
420
420
  write(e) {
421
- this.writable = !1, be(e, (t) => {
421
+ this.writable = !1, we(e, (t) => {
422
422
  this.doWrite(t, () => {
423
423
  this.writable = !0, this.emitReserved("drain");
424
424
  });
@@ -587,7 +587,7 @@ if (typeof document < "u") {
587
587
  if (typeof attachEvent == "function")
588
588
  attachEvent("onunload", j);
589
589
  else if (typeof addEventListener == "function") {
590
- const n = "onpagehide" in p ? "pagehide" : "unload";
590
+ const n = "onpagehide" in d ? "pagehide" : "unload";
591
591
  addEventListener(n, j, !1);
592
592
  }
593
593
  }
@@ -620,7 +620,7 @@ function he(n) {
620
620
  }
621
621
  if (!e)
622
622
  try {
623
- return new p[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
623
+ return new d[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
624
624
  } catch {
625
625
  }
626
626
  }
@@ -681,7 +681,7 @@ class Me extends K {
681
681
  return this.opts.timestampRequests && (t[this.opts.timestampParam] = ce()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
682
682
  }
683
683
  }
684
- const I = p.WebSocket || p.MozWebSocket;
684
+ const I = d.WebSocket || d.MozWebSocket;
685
685
  class Fe extends Me {
686
686
  createSocket(e, t, s) {
687
687
  return _e ? new I(e, t, s) : t ? new I(e, t) : new I(e);
@@ -780,7 +780,7 @@ const M = typeof addEventListener == "function" && typeof removeEventListener ==
780
780
  M && addEventListener("offline", () => {
781
781
  x.forEach((n) => n());
782
782
  }, !1);
783
- class w extends u {
783
+ class b extends u {
784
784
  /**
785
785
  * Socket constructor.
786
786
  *
@@ -848,7 +848,7 @@ class w extends u {
848
848
  }, 0);
849
849
  return;
850
850
  }
851
- const e = this.opts.rememberUpgrade && w.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
851
+ const e = this.opts.rememberUpgrade && b.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
852
852
  this.readyState = "opening";
853
853
  const t = this.createTransport(e);
854
854
  t.open(), this.setTransport(t);
@@ -867,7 +867,7 @@ class w extends u {
867
867
  * @private
868
868
  */
869
869
  onOpen() {
870
- this.readyState = "open", w.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
870
+ this.readyState = "open", b.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
871
871
  }
872
872
  /**
873
873
  * Handles a packet.
@@ -1031,7 +1031,7 @@ class w extends u {
1031
1031
  * @private
1032
1032
  */
1033
1033
  _onError(e) {
1034
- if (w.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1034
+ if (b.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1035
1035
  return this.transports.shift(), this._open();
1036
1036
  this.emitReserved("error", e), this._onClose("transport error", e);
1037
1037
  }
@@ -1050,8 +1050,8 @@ class w extends u {
1050
1050
  }
1051
1051
  }
1052
1052
  }
1053
- w.protocol = oe;
1054
- class Ye extends w {
1053
+ b.protocol = oe;
1054
+ class Ye extends b {
1055
1055
  constructor() {
1056
1056
  super(...arguments), this._upgrades = [];
1057
1057
  }
@@ -1068,14 +1068,14 @@ class Ye extends w {
1068
1068
  */
1069
1069
  _probe(e) {
1070
1070
  let t = this.createTransport(e), s = !1;
1071
- w.priorWebsocketSuccess = !1;
1071
+ b.priorWebsocketSuccess = !1;
1072
1072
  const i = () => {
1073
- s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (d) => {
1073
+ s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (p) => {
1074
1074
  if (!s)
1075
- if (d.type === "pong" && d.data === "probe") {
1075
+ if (p.type === "pong" && p.data === "probe") {
1076
1076
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1077
1077
  return;
1078
- w.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1078
+ b.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1079
1079
  s || this.readyState !== "closed" && (_(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1080
1080
  });
1081
1081
  } else {
@@ -1087,8 +1087,8 @@ class Ye extends w {
1087
1087
  function r() {
1088
1088
  s || (s = !0, _(), t.close(), t = null);
1089
1089
  }
1090
- const o = (d) => {
1091
- const E = new Error("probe error: " + d);
1090
+ const o = (p) => {
1091
+ const E = new Error("probe error: " + p);
1092
1092
  E.transport = t.name, r(), this.emitReserved("upgradeError", E);
1093
1093
  };
1094
1094
  function l() {
@@ -1097,8 +1097,8 @@ class Ye extends w {
1097
1097
  function c() {
1098
1098
  o("socket closed");
1099
1099
  }
1100
- function f(d) {
1101
- t && d.name !== t.name && r();
1100
+ function f(p) {
1101
+ t && p.name !== t.name && r();
1102
1102
  }
1103
1103
  const _ = () => {
1104
1104
  t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", l), this.off("close", c), this.off("upgrading", f);
@@ -1540,8 +1540,8 @@ class fe extends u {
1540
1540
  data: t
1541
1541
  };
1542
1542
  if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1543
- const _ = this.ids++, d = t.pop();
1544
- this._registerAckCallback(_, d), o.id = _;
1543
+ const _ = this.ids++, p = t.pop();
1544
+ this._registerAckCallback(_, p), o.id = _;
1545
1545
  }
1546
1546
  const l = (i = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || i === void 0 ? void 0 : i.writable, c = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
1547
1547
  return this.flags.volatile && !l || (c ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
@@ -2286,7 +2286,7 @@ class Z extends CustomEvent {
2286
2286
  super(e, t);
2287
2287
  }
2288
2288
  }
2289
- class de extends EventTarget {
2289
+ class pe extends EventTarget {
2290
2290
  __listeners__ = {
2291
2291
  debug: !1
2292
2292
  };
@@ -2387,7 +2387,7 @@ class de extends EventTarget {
2387
2387
  this.__listeners__[e] = !1;
2388
2388
  }
2389
2389
  }
2390
- class a extends de {
2390
+ class a extends pe {
2391
2391
  static instance;
2392
2392
  static devices = {};
2393
2393
  constructor() {
@@ -2579,7 +2579,7 @@ class ct {
2579
2579
  return !this.#i;
2580
2580
  }
2581
2581
  }
2582
- const b = new ct(), D = {
2582
+ const w = new ct(), D = {
2583
2583
  baudRate: 9600,
2584
2584
  dataBits: 8,
2585
2585
  stopBits: 1,
@@ -2587,7 +2587,7 @@ const b = new ct(), D = {
2587
2587
  bufferSize: 32768,
2588
2588
  flowControl: "none"
2589
2589
  };
2590
- class ht extends de {
2590
+ class ht extends pe {
2591
2591
  __internal__ = {
2592
2592
  bypassSerialBytesConnection: !1,
2593
2593
  auto_response: !1,
@@ -2642,8 +2642,11 @@ class ht extends de {
2642
2642
  auto_response: null,
2643
2643
  free_timeout_ms: 50,
2644
2644
  // In previous versions 400 was used
2645
- useRTSCTS: !1
2645
+ useRTSCTS: !1,
2646
2646
  // Use RTS/CTS flow control
2647
+ pipeAbortController: null,
2648
+ pipeDone: null,
2649
+ pumpReader: null
2647
2650
  },
2648
2651
  device: {
2649
2652
  type: "unknown",
@@ -2682,7 +2685,14 @@ class ht extends de {
2682
2685
  }) {
2683
2686
  if (super(), !("serial" in navigator))
2684
2687
  throw new Error("Web Serial not supported");
2685
- e && (this.serialFilters = e), t && (this.serialConfigPort = t), r && (this.__internal__.bypassSerialBytesConnection = r), s && this.#v(s), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), this.__internal__.serial.socket = o, this.__internal__.serial.transformStream = l, this.#g(), this.#m();
2688
+ if (e && (this.serialFilters = e), t && (this.serialConfigPort = t), r && (this.__internal__.bypassSerialBytesConnection = r), s && this.#v(s), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), this.__internal__.serial.socket = o, typeof l == "function")
2689
+ this.__internal__.serial.transformStream = l;
2690
+ else if (l) {
2691
+ const c = l;
2692
+ this.__internal__.serial.transformStream = () => c;
2693
+ } else
2694
+ this.__internal__.serial.transformStream = !1;
2695
+ this.#g(), this.#m();
2686
2696
  }
2687
2697
  set listenOnChannel(e) {
2688
2698
  if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
@@ -2898,7 +2908,7 @@ class ht extends de {
2898
2908
  };
2899
2909
  }
2900
2910
  #t(e) {
2901
- return this.useSocket ? this.__internal__.serial.connected && b.isConnected() : !!(e && e.readable && e.writable);
2911
+ return this.useSocket ? this.__internal__.serial.connected && w.isConnected() : !!(e && e.readable && e.writable);
2902
2912
  }
2903
2913
  async timeout(e, t) {
2904
2914
  this.__internal__.last_error.message = "Operation response timed out.", this.__internal__.last_error.action = t, this.__internal__.last_error.code = e, this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), t === "connect" ? (this.__internal__.serial.connected = !1, this.dispatch("serial:reconnect", {}), a.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, a.$dispatchChange(this), await this.serialConnect()), this.__internal__.serial.queue.length > 0 && this.dispatch("internal:queue", {}), this.dispatch("serial:timeout", {
@@ -2938,29 +2948,38 @@ class ht extends de {
2938
2948
  async serialDisconnect() {
2939
2949
  try {
2940
2950
  if (this.useSocket)
2941
- b.isConnected() && b.disconnectDevice(this.configDeviceSocket);
2951
+ w.isConnected() && w.disconnectDevice(this.configDeviceSocket);
2942
2952
  else {
2943
2953
  this.__internal__.serial.keep_reading = !1;
2944
- const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
2945
- if (e && (await e.cancel().catch((s) => this.serialErrors(s)), this.__internal__.serial.input_done && await this.__internal__.serial.input_done), t) {
2954
+ const e = this.__internal__.serial.reader;
2955
+ e && await e.cancel().catch(() => {
2956
+ }), this.__internal__.serial.pumpReader && await this.__internal__.serial.pumpReader.cancel().catch(() => {
2957
+ }), this.__internal__.serial.pipeDone && (await this.__internal__.serial.pipeDone.catch(() => {
2958
+ }), this.__internal__.serial.pipeDone = null), this.__internal__.serial.input_done && await this.__internal__.serial.input_done.catch(() => {
2959
+ });
2960
+ const t = this.__internal__.serial.output_stream;
2961
+ if (t) {
2946
2962
  const s = t.getWriter();
2947
- await s.close(), s.releaseLock(), this.__internal__.serial.output_done && await this.__internal__.serial.output_done;
2963
+ await s.close().catch(() => {
2964
+ }), s.releaseLock(), this.__internal__.serial.output_done && await this.__internal__.serial.output_done.catch(() => {
2965
+ });
2948
2966
  }
2949
- this.__internal__.serial && this.__internal__.serial.connected && this.__internal__.serial.port && await this.__internal__.serial.port.close();
2967
+ this.__internal__.serial.port && await this.__internal__.serial.port.close().catch(() => {
2968
+ });
2950
2969
  }
2951
2970
  } catch (e) {
2952
- this.serialErrors(e);
2971
+ console.error(e), this.serialErrors(e);
2953
2972
  } finally {
2954
- this.__internal__.serial.reader = null, this.__internal__.serial.input_done = null, this.__internal__.serial.output_stream = null, this.__internal__.serial.output_done = null, this.__internal__.serial.connected = !1, this.__internal__.serial.port = null, a.$dispatchChange(this);
2973
+ this.__internal__.serial.reader = null, this.__internal__.serial.input_done = null, this.__internal__.serial.output_stream = null, this.__internal__.serial.output_done = null, this.__internal__.serial.keep_reading = !0, this.__internal__.serial.connected = !1, this.__internal__.serial.port = null, a.$dispatchChange(this);
2955
2974
  }
2956
2975
  }
2957
2976
  async #o(e) {
2958
- if (b.isDisconnected())
2977
+ if (w.isDisconnected())
2959
2978
  throw this.#e({ error: "Socket is disconnected." }), new Error("The socket is disconnected");
2960
2979
  if (this.isDisconnected)
2961
2980
  throw this.#e({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
2962
2981
  const t = this.validateBytes(e);
2963
- b.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2982
+ w.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2964
2983
  }
2965
2984
  async #s(e) {
2966
2985
  if (this.useSocket) {
@@ -3116,7 +3135,7 @@ class ht extends de {
3116
3135
  }, this.__internal__.serial.free_timeout_ms || 50));
3117
3136
  }
3118
3137
  }
3119
- async #d() {
3138
+ async #p() {
3120
3139
  const {
3121
3140
  limiter: e,
3122
3141
  prefixLimiter: t = !1,
@@ -3151,14 +3170,14 @@ class ht extends de {
3151
3170
  o.push(new TextEncoder().encode(c[1])), f = _.lastIndex;
3152
3171
  } else if (s)
3153
3172
  for (; (c = e.exec(r)) !== null; ) {
3154
- const _ = c.index, d = r.slice(f, _);
3155
- o.push(new TextEncoder().encode(d)), f = e.lastIndex;
3173
+ const _ = c.index, p = r.slice(f, _);
3174
+ o.push(new TextEncoder().encode(p)), f = e.lastIndex;
3156
3175
  }
3157
3176
  else if (t) {
3158
3177
  const _ = r.split(e);
3159
3178
  _.shift();
3160
- for (const d of _)
3161
- o.push(new TextEncoder().encode(d));
3179
+ for (const p of _)
3180
+ o.push(new TextEncoder().encode(p));
3162
3181
  r = "";
3163
3182
  }
3164
3183
  r = r.slice(f);
@@ -3170,16 +3189,43 @@ class ht extends de {
3170
3189
  this.#r(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
3171
3190
  }, this.__internal__.serial.free_timeout_ms ?? 50));
3172
3191
  }
3173
- async #p() {
3192
+ async #d() {
3174
3193
  const e = this.__internal__.serial.port;
3175
3194
  if (!e || !e.readable) throw new Error("Port is not readable");
3176
- const t = this.__internal__.serial.transformStream ? this.__internal__.serial.transformStream : null, s = t ? e.readable.pipeThrough(t).getReader() : e.readable.getReader();
3195
+ const t = this.__internal__.serial.transformStream;
3196
+ let s;
3197
+ if (t) {
3198
+ const i = t(), r = e.readable.getReader();
3199
+ this.__internal__.serial.pumpReader = r;
3200
+ const o = i.writable.getWriter();
3201
+ this.__internal__.serial.pipeDone = (async () => {
3202
+ try {
3203
+ for (; ; ) {
3204
+ const { value: l, done: c } = await r.read();
3205
+ if (c) break;
3206
+ await o.write(l);
3207
+ }
3208
+ } catch {
3209
+ } finally {
3210
+ try {
3211
+ r.releaseLock();
3212
+ } catch {
3213
+ }
3214
+ try {
3215
+ o.releaseLock();
3216
+ } catch {
3217
+ }
3218
+ this.__internal__.serial.pumpReader = null;
3219
+ }
3220
+ })(), s = i.readable.getReader();
3221
+ } else
3222
+ s = e.readable.getReader();
3177
3223
  this.__internal__.serial.reader = s;
3178
3224
  try {
3179
3225
  for (; this.__internal__.serial.keep_reading; ) {
3180
3226
  const { value: i, done: r } = await s.read();
3181
3227
  if (r) break;
3182
- this.#h(i), this.__internal__.serial.transformStream ? await this.#_() : this.__internal__.serial.response.delimited ? await this.#d() : this.__internal__.serial.response.length === null ? await this.#u() : await this.#f();
3228
+ this.#h(i), t ? await this.#_() : this.__internal__.serial.response.delimited ? await this.#p() : this.__internal__.serial.response.length === null ? await this.#u() : await this.#f();
3183
3229
  }
3184
3230
  } catch (i) {
3185
3231
  this.serialErrors(i);
@@ -3193,11 +3239,11 @@ class ht extends de {
3193
3239
  async serialConnect() {
3194
3240
  try {
3195
3241
  if (this.#a(!0), this.useSocket) {
3196
- if (b.prepare(), this.__internal__.serial.last_action = "connect", this.__internal__.timeout.until_response = setTimeout(async () => {
3242
+ if (w.prepare(), this.__internal__.serial.last_action = "connect", this.__internal__.timeout.until_response = setTimeout(async () => {
3197
3243
  await this.timeout(this.__internal__.serial.bytes_connection ?? [], "connection:start");
3198
- }, this.__internal__.time.response_connection), b.isDisconnected())
3244
+ }, this.__internal__.time.response_connection), w.isDisconnected())
3199
3245
  return;
3200
- b.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3246
+ w.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3201
3247
  action: "connect",
3202
3248
  bytes: this.__internal__.serial.bytes_connection
3203
3249
  });
@@ -3225,7 +3271,7 @@ class ht extends de {
3225
3271
  }, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#s(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
3226
3272
  action: "connect",
3227
3273
  bytes: this.__internal__.serial.bytes_connection
3228
- }), this.__internal__.auto_response && this.#r(this.__internal__.serial.auto_response), await this.#p();
3274
+ }), this.__internal__.auto_response && this.#r(this.__internal__.serial.auto_response), this.__internal__.serial.input_done = this.#d(), await this.__internal__.serial.input_done;
3229
3275
  }
3230
3276
  } catch (e) {
3231
3277
  this.#a(!1), this.serialErrors(e);
@@ -3279,7 +3325,7 @@ class ht extends de {
3279
3325
  #m() {
3280
3326
  const e = this;
3281
3327
  this.on("internal:queue", async () => {
3282
- await e.#w();
3328
+ await e.#b();
3283
3329
  });
3284
3330
  const t = () => {
3285
3331
  e.isConnected && e.#e({ error: "Socket disconnected." });
@@ -3287,17 +3333,17 @@ class ht extends de {
3287
3333
  e.isDisconnected && !e.isConnecting && e.serialConnect().catch(() => {
3288
3334
  });
3289
3335
  };
3290
- this.useSocket && (window.addEventListener("serial:socket:disconnected", t), window.addEventListener("serial:socket:connected", s)), this.#b();
3336
+ this.useSocket && (window.addEventListener("serial:socket:disconnected", t), window.addEventListener("serial:socket:connected", s)), this.#w();
3291
3337
  }
3292
- #b() {
3338
+ #w() {
3293
3339
  const e = this;
3294
3340
  navigator.serial.addEventListener("connect", async () => {
3295
3341
  e.isDisconnected && await e.serialConnect().catch(() => {
3296
3342
  });
3297
3343
  });
3298
3344
  }
3299
- async #w() {
3300
- if (this.useSocket && b.isDisconnected())
3345
+ async #b() {
3346
+ if (this.useSocket && w.isDisconnected())
3301
3347
  return;
3302
3348
  if (!this.#t(this.__internal__.serial.port)) {
3303
3349
  this.#e({ error: "Port is closed, not readable or writable." }), await this.serialConnect();
@@ -3459,7 +3505,7 @@ class ht extends de {
3459
3505
  }
3460
3506
  }
3461
3507
  export {
3462
- ht as T,
3463
- b as c,
3464
- a as s
3508
+ w as h,
3509
+ a as s,
3510
+ ht as v
3465
3511
  };