jsgotty 0.9.1 → 1.1.1

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.
@@ -12192,6 +12192,7 @@
12192
12192
  this.reconnectToken = "";
12193
12193
  this.reconnectDeadline = 0;
12194
12194
  this.reconnectAttempts = 0;
12195
+ this.zmodemExpectedSeq = 0;
12195
12196
  }
12196
12197
  open() {
12197
12198
  let e;
@@ -12263,6 +12264,19 @@
12263
12264
  }, 3e4)));
12264
12265
  }),
12265
12266
  r.onReceive((e) => {
12267
+ if ("string" != typeof e) {
12268
+ const i =
12269
+ e instanceof ArrayBuffer
12270
+ ? new Uint8Array(e)
12271
+ : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
12272
+ if (0 === i.length) return;
12273
+ switch (String.fromCharCode(i[0])) {
12274
+ case t.msgOutput:
12275
+ this.term.output(i.subarray(1));
12276
+ break;
12277
+ }
12278
+ return;
12279
+ }
12266
12280
  const i = e.slice(1);
12267
12281
  switch (e[0]) {
12268
12282
  case t.msgOutput:
@@ -12270,6 +12284,43 @@
12270
12284
  Uint8Array.from(atob(i), (e) => e.charCodeAt(0)),
12271
12285
  );
12272
12286
  break;
12287
+ case "y": {
12288
+ const e = i.indexOf(":");
12289
+ if (e === -1) break;
12290
+ const s = i.indexOf(":", e + 1);
12291
+ let r;
12292
+ let n;
12293
+ let o;
12294
+ if (s === -1) {
12295
+ r = null;
12296
+ n = Number.parseInt(i.slice(0, e), 10);
12297
+ o = i.slice(e + 1);
12298
+ } else {
12299
+ r = Number.parseInt(i.slice(0, e), 10);
12300
+ n = Number.parseInt(i.slice(e + 1, s), 10);
12301
+ o = i.slice(s + 1);
12302
+ }
12303
+ if (!Number.isFinite(n)) break;
12304
+ if (Number.isFinite(r) && r !== this.zmodemStreamId) {
12305
+ this.zmodemStreamId = r;
12306
+ this.zmodemExpectedSeq = 0;
12307
+ }
12308
+ if (n === this.zmodemExpectedSeq) {
12309
+ this.term.output(
12310
+ Uint8Array.from(atob(o), (e) =>
12311
+ e.charCodeAt(0),
12312
+ ),
12313
+ );
12314
+ this.zmodemExpectedSeq = n + 1;
12315
+ } else if (n > this.zmodemExpectedSeq) {
12316
+ window.__gottyZmodemDebug &&
12317
+ window.__gottyZmodemDebug(
12318
+ `zmodem chunk gap got=${n} expected=${this.zmodemExpectedSeq}`,
12319
+ );
12320
+ }
12321
+ this.connection.send("Y" + String(this.zmodemExpectedSeq - 1));
12322
+ break;
12323
+ }
12273
12324
  case t.msgPong:
12274
12325
  break;
12275
12326
  case t.msgSetWindowTitle:
@@ -12362,6 +12413,13 @@
12362
12413
  sendSetEncoding(e) {
12363
12414
  this.connection.send(t.msgSetEncoding + e);
12364
12415
  }
12416
+ sendZmodemMode(e) {
12417
+ if (!e) {
12418
+ this.zmodemExpectedSeq = 0;
12419
+ this.zmodemStreamId = null;
12420
+ }
12421
+ this.connection.send("z" + (e ? "1" : "0"));
12422
+ }
12365
12423
  };
12366
12424
  },
12367
12425
  616: (e) => {
@@ -12454,18 +12512,60 @@
12454
12512
  zmodemAddon;
12455
12513
  toServer;
12456
12514
  encoder;
12457
- reconnectAction;
12458
- constructor(e) {
12459
- ((this.elem = e),
12460
- (this.term = new r.Terminal()),
12461
- (this.fitAddOn = new s.FitAddon()),
12462
- (this.zmodemAddon = new a.ZModemAddon({
12463
- toTerminal: (e) => this.term.write(e),
12464
- toServer: (e) => this.sendInput(e),
12465
- })),
12466
- this.term.loadAddon(new n.WebLinksAddon()),
12467
- this.term.loadAddon(this.fitAddOn),
12468
- this.term.loadAddon(this.zmodemAddon),
12515
+ fontFamilyOverride;
12516
+ fontSizeOverride;
12517
+ reconnectAction;
12518
+ constructor(e, t = {}) {
12519
+ const fontFamilyValue =
12520
+ "string" == typeof t["font-family"] && t["font-family"].trim()
12521
+ ? t["font-family"].trim()
12522
+ : null;
12523
+ const parsedFontSize = Number(t["font-size"]);
12524
+ const fontSizeValue =
12525
+ Number.isFinite(parsedFontSize) && parsedFontSize > 0
12526
+ ? parsedFontSize
12527
+ : null;
12528
+ ((this.elem = e),
12529
+ (this.fontFamilyOverride = fontFamilyValue),
12530
+ (this.fontSizeOverride = fontSizeValue),
12531
+ (this.term = new r.Terminal({
12532
+ allowProposedApi: !0,
12533
+ customGlyphs: !0,
12534
+ rescaleOverlappingGlyphs: !0,
12535
+ fontFamily:
12536
+ fontFamilyValue ||
12537
+ "DejaVu Sans Mono, Everson Mono, FreeMono, Menlo, Terminal, monospace, Apple Symbols",
12538
+ fontSize: fontSizeValue || 15,
12539
+ })),
12540
+ (this.fitAddOn = new s.FitAddon()),
12541
+ (this.zmodemAddon = new a.ZModemAddon({
12542
+ toTerminal: (e) => this.term.write(e),
12543
+ toServer: (e) => this.sendInput(e),
12544
+ })),
12545
+ this.setPreferences(t),
12546
+ (() => {
12547
+ try {
12548
+ const e = globalThis.Unicode11Addon;
12549
+ const t =
12550
+ e && "function" == typeof e
12551
+ ? e
12552
+ : e && "function" == typeof e.Unicode11Addon
12553
+ ? e.Unicode11Addon
12554
+ : null;
12555
+ if (!t) return;
12556
+ const s = new t();
12557
+ this.term.loadAddon(s),
12558
+ (this.term.unicode.activeVersion = "11");
12559
+ } catch (e) {
12560
+ console.warn(
12561
+ "Unicode11 addon failed to load, using the default width table",
12562
+ e,
12563
+ );
12564
+ }
12565
+ })(),
12566
+ this.term.loadAddon(new n.WebLinksAddon()),
12567
+ this.term.loadAddon(this.fitAddOn),
12568
+ this.term.loadAddon(this.zmodemAddon),
12469
12569
  (e.__gottyXterm = this.term),
12470
12570
  (window.getTerminalText = () => {
12471
12571
  const e = this.term.buffer.active;
@@ -12577,11 +12677,14 @@
12577
12677
  }
12578
12678
  setPreferences(e) {
12579
12679
  Object.keys(e).forEach((t) => {
12580
- "EnableWebGL" == t && t
12680
+ "EnableWebGL" == t && e[t]
12581
12681
  ? this.term.loadAddon(new o.WebglAddon())
12582
12682
  : "font-size" == t
12583
- ? (this.term.options.fontSize = e[t])
12584
- : "font-family" == t && (this.term.options.fontFamily = e[t]);
12683
+ ? (this.term.options.fontSize =
12684
+ this.fontSizeOverride || e[t])
12685
+ : "font-family" == t &&
12686
+ (this.term.options.fontFamily =
12687
+ this.fontFamilyOverride || e[t]);
12585
12688
  });
12586
12689
  }
12587
12690
  sendInput(e) {
@@ -12779,7 +12882,16 @@
12779
12882
  document.body.prepend(this.elem));
12780
12883
  }
12781
12884
  consume(e) {
12782
- this.sentry.consume(e);
12885
+ try {
12886
+ this.sentry.consume(e);
12887
+ } catch (e) {
12888
+ (console.error(e),
12889
+ window.__gottyZmodemDebug &&
12890
+ window.__gottyZmodemDebug(
12891
+ `consume error ${e && e.message ? e.message : e}`,
12892
+ ));
12893
+ throw e;
12894
+ }
12783
12895
  }
12784
12896
  activate(e) {
12785
12897
  this.term = e;
@@ -12804,52 +12916,285 @@
12804
12916
  onDetect(e) {
12805
12917
  var t = e.confirm();
12806
12918
  ((this.term.options.disableStdin = !0),
12919
+ window.__gottyWebTTY &&
12920
+ window.__gottyWebTTY.sendZmodemMode &&
12921
+ window.__gottyWebTTY.sendZmodemMode(!0),
12807
12922
  t.on("session_end", () => {
12808
- this.reset();
12923
+ window.__gottyWebTTY &&
12924
+ window.__gottyWebTTY.sendZmodemMode &&
12925
+ window.__gottyWebTTY.sendZmodemMode(!1);
12809
12926
  }),
12810
12927
  "send" === t.type
12811
12928
  ? this.send(t)
12812
- : (t.on("offer", (e) => this.onOffer(e)), t.start()));
12929
+ : (t.on("offer", (e) => this.onOffer(t, e)), t.start()));
12813
12930
  }
12814
12931
  send(e) {
12815
- (0, s.render)((0, r.jsx)(c, { session: e }), this.elem);
12932
+ (0, s.render)(
12933
+ (0, r.jsx)(c, { session: e, onFinish: () => this.reset() }),
12934
+ this.elem,
12935
+ );
12816
12936
  }
12817
- onOffer(e) {
12937
+ onOffer(e, t) {
12818
12938
  (0, s.render)(
12819
- (0, r.jsx)(l, { xfer: e, onFinish: () => this.reset() }),
12939
+ (0, r.jsx)(l, { session: e, xfer: t, onFinish: () => this.reset() }),
12820
12940
  this.elem,
12821
12941
  );
12822
12942
  }
12823
12943
  };
12824
12944
  class l extends s.Component {
12825
12945
  constructor(e) {
12826
- (super(e), this.setState({ state: "notstarted" }));
12946
+ (super(e),
12947
+ (this.debugLines = []),
12948
+ (this.debugInputBytes = 0),
12949
+ (this.debugReceiveBytes = 0),
12950
+ (this.receiveDone = !1),
12951
+ (this.sessionEnded = !1),
12952
+ (this.finishDone = !1),
12953
+ (this.finishTimer = null),
12954
+ this.setState({ state: "notstarted" }));
12955
+ }
12956
+ debug(e) {
12957
+ const t = new Date().toLocaleTimeString();
12958
+ const i = `${t} ${e}`;
12959
+ (console.log("[zmodem-recv]", i),
12960
+ this.debugLines.push(i),
12961
+ 80 < this.debugLines.length && this.debugLines.shift(),
12962
+ this.forceUpdate());
12963
+ }
12964
+ attachDebugEvents() {
12965
+ if (this.debugAttached || !this.props.session) return;
12966
+ this.debugAttached = !0;
12967
+ this.props.session.on("receive", (e) => {
12968
+ if (e && e.NAME) {
12969
+ this.debug(`rx header ${e.NAME}`);
12970
+ return;
12971
+ }
12972
+ if (e && e.get_payload) {
12973
+ const t = e.get_payload();
12974
+ this.debugReceiveBytes += t ? t.length : 0;
12975
+ if (
12976
+ this.debugReceiveBytes - (this.lastDebugReceiveBytes || 0) >=
12977
+ 4 * 1024 * 1024
12978
+ ) {
12979
+ this.lastDebugReceiveBytes = this.debugReceiveBytes;
12980
+ this.debug(
12981
+ `rx data ${this.debugReceiveBytes.toLocaleString()} bytes`,
12982
+ );
12983
+ }
12984
+ }
12985
+ });
12986
+ this.props.session.on("session_end", () => {
12987
+ this.debug("session_end");
12988
+ this.sessionEnded = !0;
12989
+ this.finishIfReady();
12990
+ });
12991
+ this.props.xfer.on("complete", () => {
12992
+ this.debug("xfer complete event");
12993
+ });
12827
12994
  }
12828
- accept() {
12995
+ async accept() {
12996
+ this.cancelled = !1;
12997
+ this.attachDebugEvents();
12998
+ window.__gottyZmodemDebug = (e) => this.debug(e);
12999
+ this.debug(
13000
+ `accept ${this.props.xfer.get_details().name} ${this.props.xfer
13001
+ .get_details()
13002
+ .size.toLocaleString()} bytes`,
13003
+ );
12829
13004
  this.setState({ state: "started" });
12830
13005
  let e = setInterval(() => this.forceUpdate(), 100);
12831
- this.props.xfer.accept().then((t) => {
12832
- (clearInterval(e),
12833
- this.forceUpdate(),
12834
- "skipped" != this.state.state &&
12835
- d.save_to_disk(t, this.props.xfer.get_details().name),
12836
- this.setState({ state: "done" }));
12837
- });
13006
+ const t = this.props.xfer.get_details().name;
13007
+ let i = null;
13008
+ this.writer = null;
13009
+ let n = Promise.resolve();
13010
+ let o = !1;
13011
+ const a = 4 * 1024 * 1024;
13012
+ let l = [];
13013
+ let c = 0;
13014
+ const h = () => {
13015
+ if (0 === c) return;
13016
+ const e = new Uint8Array(c);
13017
+ let t = 0;
13018
+ for (const i of l) {
13019
+ e.set(i, t);
13020
+ t += i.byteLength;
13021
+ }
13022
+ l = [];
13023
+ c = 0;
13024
+ n = n.then(() => i.write(e));
13025
+ };
13026
+ try {
13027
+ if (
13028
+ "function" == typeof window.showSaveFilePicker &&
13029
+ "skipped" != this.state.state
13030
+ ) {
13031
+ const e = await window.showSaveFilePicker({
13032
+ suggestedName: t,
13033
+ });
13034
+ this.debug("save picker accepted");
13035
+ i = await e.createWritable();
13036
+ this.debug("writable opened");
13037
+ this.writer = i;
13038
+ o = !0;
13039
+ await this.props.xfer.accept({
13040
+ on_input: (e) => {
13041
+ if (this.cancelled) return;
13042
+ const t = new Uint8Array(e);
13043
+ this.debugInputBytes += t.byteLength;
13044
+ if (
13045
+ this.debugInputBytes - (this.lastDebugInputBytes || 0) >=
13046
+ 4 * 1024 * 1024
13047
+ ) {
13048
+ this.lastDebugInputBytes = this.debugInputBytes;
13049
+ this.debug(
13050
+ `on_input ${this.debugInputBytes.toLocaleString()} bytes`,
13051
+ );
13052
+ }
13053
+ (l.push(t), (c += t.byteLength), c >= a && h());
13054
+ },
13055
+ });
13056
+ if (this.cancelled) return;
13057
+ this.debug("xfer.accept resolved");
13058
+ this.setState({ state: "finishing" });
13059
+ h();
13060
+ this.debug("waiting queued writes");
13061
+ await n;
13062
+ if (this.cancelled) return;
13063
+ this.debug("closing writable");
13064
+ await i.close();
13065
+ this.debug("writable closed");
13066
+ } else {
13067
+ this.debug("fallback blob receive");
13068
+ o = !0;
13069
+ const e = await this.props.xfer.accept();
13070
+ this.debug("fallback xfer.accept resolved");
13071
+ "skipped" != this.state.state && d.save_to_disk(e, t);
13072
+ }
13073
+ this.debug("receive done");
13074
+ this.receiveDone = !0;
13075
+ (this.forceUpdate(),
13076
+ this.setState({
13077
+ state: this.props.session.has_ended() ? "done" : "finishing",
13078
+ }));
13079
+ if (this.props.session.has_ended()) {
13080
+ this.sessionEnded = !0;
13081
+ }
13082
+ if (!this.finishIfReady()) {
13083
+ this.debug("waiting session_end");
13084
+ this.scheduleFinishFallback();
13085
+ }
13086
+ } catch (t) {
13087
+ this.debug(`error ${t && t.message ? t.message : t}`);
13088
+ (i &&
13089
+ i.abort &&
13090
+ i.abort().catch(() => {}),
13091
+ !o &&
13092
+ this.props.xfer.skip &&
13093
+ this.props.xfer.skip(),
13094
+ console.error(t),
13095
+ !this.cancelled && this.setState({ state: "notstarted" }));
13096
+ } finally {
13097
+ clearInterval(e);
13098
+ if (this.finishTimer && this.finishDone) {
13099
+ clearTimeout(this.finishTimer);
13100
+ this.finishTimer = null;
13101
+ }
13102
+ if (window.__gottyZmodemDebug) {
13103
+ window.__gottyZmodemDebug = null;
13104
+ }
13105
+ this.writer = null;
13106
+ }
12838
13107
  }
12839
13108
  finish() {
12840
13109
  (console.log("finished"),
12841
13110
  this.props.onFinish && this.props.onFinish());
12842
13111
  }
13112
+ finishIfReady() {
13113
+ if (!this.receiveDone || !this.sessionEnded) {
13114
+ return !1;
13115
+ }
13116
+ this.completeFinish();
13117
+ return !0;
13118
+ }
13119
+ scheduleFinishFallback() {
13120
+ if (this.finishTimer || this.finishDone) {
13121
+ return;
13122
+ }
13123
+ this.finishTimer = setTimeout(() => {
13124
+ this.finishTimer = null;
13125
+ if (this.finishDone || !this.receiveDone) {
13126
+ return;
13127
+ }
13128
+ this.debug("forcing finish after receive completion");
13129
+ window.__gottyWebTTY &&
13130
+ window.__gottyWebTTY.sendZmodemMode &&
13131
+ window.__gottyWebTTY.sendZmodemMode(!1);
13132
+ this.completeFinish();
13133
+ }, 800);
13134
+ }
13135
+ completeFinish() {
13136
+ if (this.finishDone) {
13137
+ return;
13138
+ }
13139
+ this.finishDone = !0;
13140
+ if (this.finishTimer) {
13141
+ clearTimeout(this.finishTimer);
13142
+ this.finishTimer = null;
13143
+ }
13144
+ this.setState({ state: "done" });
13145
+ this.props.onFinish && this.props.onFinish();
13146
+ }
12843
13147
  progress() {
12844
- if ("notstarted" !== this.state.state)
12845
- return (0, r.jsx)(a, {
12846
- min: 0,
12847
- max: this.props.xfer.get_details().size,
12848
- now: this.props.xfer.get_offset(),
13148
+ if ("notstarted" !== this.state.state) {
13149
+ const e = this.props.xfer.get_details();
13150
+ const t = Number.isFinite(e.size) ? e.size : 0;
13151
+ const i = this.props.xfer.get_offset() || 0;
13152
+ return (0, r.jsxs)(r.Fragment, {
13153
+ children: [
13154
+ (0, r.jsx)(a, {
13155
+ min: 0,
13156
+ max: t || 1,
13157
+ now: i,
13158
+ }),
13159
+ (0, r.jsxs)("div", {
13160
+ style: "font-size: 12px; margin-top: 4px;",
13161
+ children: [
13162
+ i.toLocaleString(),
13163
+ " / ",
13164
+ t.toLocaleString(),
13165
+ " bytes",
13166
+ e.name
13167
+ ? ` - ${e.name}`
13168
+ : "",
13169
+ ],
13170
+ }),
13171
+ ],
12849
13172
  });
13173
+ }
12850
13174
  }
12851
13175
  skip() {
12852
- (this.props.xfer.skip(), this.setState({ state: "skipped" }));
13176
+ (this.debug("decline/skip"),
13177
+ window.__gottyWebTTY &&
13178
+ window.__gottyWebTTY.sendZmodemMode &&
13179
+ window.__gottyWebTTY.sendZmodemMode(!1),
13180
+ this.props.xfer.skip(),
13181
+ this.setState({ state: "skipped" }));
13182
+ }
13183
+ cancel() {
13184
+ this.cancelled = !0;
13185
+ this.debug("cancel -> session.abort");
13186
+ this.setState({ state: "skipped" });
13187
+ window.__gottyWebTTY &&
13188
+ window.__gottyWebTTY.sendZmodemMode &&
13189
+ window.__gottyWebTTY.sendZmodemMode(!1);
13190
+ try {
13191
+ this.props.session && this.props.session.abort();
13192
+ } catch (e) {
13193
+ console.error(e);
13194
+ }
13195
+ if (this.writer && this.writer.abort) {
13196
+ this.writer.abort().catch(() => {});
13197
+ }
12853
13198
  }
12854
13199
  buttons() {
12855
13200
  switch (this.state.state) {
@@ -12873,11 +13218,12 @@
12873
13218
  ],
12874
13219
  });
12875
13220
  case "started":
13221
+ case "finishing":
12876
13222
  return (0, r.jsx)(r.Fragment, {
12877
13223
  children: (0, r.jsx)(o.Button, {
12878
13224
  priority: "danger",
12879
13225
  clickHandler: () => {
12880
- this.skip();
13226
+ this.cancel();
12881
13227
  },
12882
13228
  children: "Cancel",
12883
13229
  }),
@@ -12908,6 +13254,14 @@
12908
13254
  .size.toLocaleString(void 0, { maximumFractionDigits: 0 }),
12909
13255
  " bytes)?",
12910
13256
  this.progress(),
13257
+ "finishing" === this.state.state
13258
+ ? (0, r.jsx)("div", { children: "Finishing..." })
13259
+ : null,
13260
+ (0, r.jsx)("pre", {
13261
+ style:
13262
+ "max-height: 220px; overflow: auto; white-space: pre-wrap; margin-top: 8px; font-size: 11px;",
13263
+ children: this.debugLines.join("\n"),
13264
+ }),
12911
13265
  ],
12912
13266
  });
12913
13267
  }
@@ -12916,7 +13270,56 @@
12916
13270
  class c extends s.Component {
12917
13271
  filePickerRef = (0, s.createRef)();
12918
13272
  constructor(e) {
12919
- (super(e), this.setState({ state: "notstarted" }));
13273
+ (super(e),
13274
+ (this.debugLines = []),
13275
+ (this.sentBytes = 0),
13276
+ (this.totalBytes = 0),
13277
+ (this.currentFileName = ""),
13278
+ this.setState({ state: "notstarted" }));
13279
+ }
13280
+ debug(e) {
13281
+ const t = new Date().toLocaleTimeString();
13282
+ const i = `${t} ${e}`;
13283
+ (console.log("[zmodem-send]", i),
13284
+ this.debugLines.push(i),
13285
+ 80 < this.debugLines.length && this.debugLines.shift(),
13286
+ this.forceUpdate());
13287
+ }
13288
+ attachDebugEvents() {
13289
+ if (this.debugAttached || !this.props.session) return;
13290
+ this.debugAttached = !0;
13291
+ this.props.session.on("receive", (e) => {
13292
+ if (e && e.NAME) {
13293
+ this.debug(`rx header ${e.NAME}`);
13294
+ }
13295
+ });
13296
+ this.props.session.on("session_end", () => {
13297
+ this.debug("session_end");
13298
+ });
13299
+ }
13300
+ progress() {
13301
+ if ("notstarted" !== this.state.state)
13302
+ return (0, r.jsxs)(r.Fragment, {
13303
+ children: [
13304
+ (0, r.jsx)(a, {
13305
+ min: 0,
13306
+ max: this.totalBytes || 1,
13307
+ now: this.sentBytes,
13308
+ }),
13309
+ (0, r.jsxs)("div", {
13310
+ style: "font-size: 12px; margin-top: 4px;",
13311
+ children: [
13312
+ this.sentBytes.toLocaleString(),
13313
+ " / ",
13314
+ this.totalBytes.toLocaleString(),
13315
+ " bytes",
13316
+ this.currentFileName
13317
+ ? ` - ${this.currentFileName}`
13318
+ : "",
13319
+ ],
13320
+ }),
13321
+ ],
13322
+ });
12920
13323
  }
12921
13324
  buttons() {
12922
13325
  switch (this.state.state) {
@@ -12952,45 +13355,125 @@
12952
13355
  return;
12953
13356
  }
12954
13357
  }
12955
- send() {
12956
- d.send_files(
12957
- this.props.session,
12958
- this.filePickerRef.current.files,
12959
- {
12960
- on_offer_response: (e, t) => {
12961
- this.setState({ state: "started" });
12962
- },
12963
- },
12964
- )
12965
- .then(() => {
12966
- (this.setState({ state: "done" }),
12967
- this.props.session.close(),
12968
- void 0 !== this.props.onFinish && this.props.onFinish());
12969
- })
12970
- .catch((e) => console.log(e));
13358
+ async send() {
13359
+ this.attachDebugEvents();
13360
+ const e = Array.from(this.filePickerRef.current.files || []);
13361
+ this.totalBytes = e.reduce((e, t) => e + (t.size || 0), 0);
13362
+ this.sentBytes = 0;
13363
+ this.currentFileName = "";
13364
+ this.debug(
13365
+ `send start ${e.length} file(s), ${this.totalBytes.toLocaleString()} bytes`,
13366
+ );
13367
+ if (0 === e.length) {
13368
+ this.debug("no files selected");
13369
+ return;
13370
+ }
13371
+ this.setState({ state: "started" });
13372
+ try {
13373
+ let t = this.totalBytes;
13374
+ for (let i = 0; i < e.length; i += 1) {
13375
+ const r = e[i];
13376
+ this.currentFileName = r.name;
13377
+ const s = {
13378
+ name: r.name,
13379
+ size: r.size,
13380
+ mtime: new Date(r.lastModified),
13381
+ files_remaining: e.length - i,
13382
+ bytes_remaining: t,
13383
+ };
13384
+ const n = await this.props.session.send_offer(s);
13385
+ this.debug(
13386
+ `offer ${r.name} ${r.size.toLocaleString()} bytes -> ${
13387
+ void 0 === n ? "skipped" : "accepted"
13388
+ }`,
13389
+ );
13390
+ if (void 0 === n) {
13391
+ t -= r.size;
13392
+ continue;
13393
+ }
13394
+ const o = 64 * 1024;
13395
+ let a = 0;
13396
+ while (a < r.size) {
13397
+ const e = Math.min(a + o, r.size);
13398
+ const t = new Uint8Array(await r.slice(a, e).arrayBuffer());
13399
+ a = e;
13400
+ if (a >= r.size) {
13401
+ await n.end(t);
13402
+ } else {
13403
+ n.send(t);
13404
+ }
13405
+ this.sentBytes += t.byteLength;
13406
+ if (
13407
+ this.sentBytes - (this.lastDebugSentBytes || 0) >=
13408
+ 4 * 1024 * 1024
13409
+ ) {
13410
+ this.lastDebugSentBytes = this.sentBytes;
13411
+ this.debug(
13412
+ `tx data ${this.sentBytes.toLocaleString()} bytes`,
13413
+ );
13414
+ }
13415
+ this.forceUpdate();
13416
+ await new Promise((e) => requestAnimationFrame(e));
13417
+ }
13418
+ if (0 === r.size) {
13419
+ await n.end([]);
13420
+ }
13421
+ t -= r.size;
13422
+ this.debug(`file complete ${r.name}`);
13423
+ }
13424
+ this.debug("send complete");
13425
+ this.debug("closing session");
13426
+ await this.props.session.close();
13427
+ this.debug("session closed");
13428
+ (window.__gottyWebTTY &&
13429
+ window.__gottyWebTTY.sendZmodemMode &&
13430
+ window.__gottyWebTTY.sendZmodemMode(!1),
13431
+ window.__gottyXterm &&
13432
+ (window.__gottyXterm.options.disableStdin = !1),
13433
+ this.setState({ state: "done" }),
13434
+ void 0 !== this.props.onFinish && this.props.onFinish());
13435
+ } catch (e) {
13436
+ (this.debug(`error ${e && e.message ? e.message : e}`),
13437
+ console.log(e),
13438
+ window.__gottyWebTTY &&
13439
+ window.__gottyWebTTY.sendZmodemMode &&
13440
+ window.__gottyWebTTY.sendZmodemMode(!1),
13441
+ window.__gottyXterm &&
13442
+ (window.__gottyXterm.options.disableStdin = !1),
13443
+ void 0 !== this.props.onFinish && this.props.onFinish(),
13444
+ this.setState({ state: "notstarted" }));
13445
+ }
12971
13446
  }
12972
13447
  render() {
12973
13448
  if ("done" != this.state.state)
12974
13449
  return (0, r.jsx)(o.MyModal, {
12975
13450
  title: "Send file(s)",
12976
13451
  buttons: this.buttons(),
12977
- children: (0, r.jsxs)("div", {
12978
- class: "mb-3",
12979
- children: [
12980
- (0, r.jsx)("label", {
12981
- for: "formFileMultiple",
12982
- class: "form-label",
12983
- children: "Remote requested file transfer",
12984
- }),
12985
- (0, r.jsx)("input", {
12986
- ref: this.filePickerRef,
12987
- class: "form-control form-control-sm",
12988
- type: "file",
12989
- id: "formFileMultiple",
12990
- multiple: !0,
12991
- }),
12992
- ],
12993
- }),
13452
+ children: [
13453
+ (0, r.jsxs)("div", {
13454
+ class: "mb-3",
13455
+ children: [
13456
+ (0, r.jsx)("label", {
13457
+ for: "formFileMultiple",
13458
+ class: "form-label",
13459
+ children: "Remote requested file transfer",
13460
+ }),
13461
+ (0, r.jsx)("input", {
13462
+ ref: this.filePickerRef,
13463
+ class: "form-control form-control-sm",
13464
+ type: "file",
13465
+ id: "formFileMultiple",
13466
+ multiple: !0,
13467
+ }),
13468
+ ],
13469
+ }),
13470
+ this.progress(),
13471
+ (0, r.jsx)("pre", {
13472
+ style:
13473
+ "max-height: 220px; overflow: auto; white-space: pre-wrap; margin-top: 8px; font-size: 11px;",
13474
+ children: this.debugLines.join("\n"),
13475
+ }),
13476
+ ],
12994
13477
  });
12995
13478
  }
12996
13479
  }
@@ -30015,6 +30498,7 @@
30015
30498
  bare;
30016
30499
  constructor(e, t) {
30017
30500
  this.bare = new WebSocket(e, t);
30501
+ this.bare.binaryType = "arraybuffer";
30018
30502
  }
30019
30503
  open() {}
30020
30504
  close() {
@@ -30062,7 +30546,7 @@
30062
30546
  i(182),
30063
30547
  i(959),
30064
30548
  ));
30065
- const s = ["CANFDX", "CANOVIO", "CANFC32"],
30549
+ const s = ["CANFDX", "CANOVIO", "CANFC32", "ESCCTL"],
30066
30550
  n = "spool_uint8array",
30067
30551
  o = [79, 79],
30068
30552
  a = r.ZMLIB.ABORT_SEQUENCE;
@@ -30391,11 +30875,21 @@
30391
30875
  this._consume_ZDATA_data),
30392
30876
  (this._next_header_handler = {
30393
30877
  ZEOF: function (t) {
30394
- (this._consume_ZEOF(t),
30878
+ (window.__gottyZmodemDebug &&
30879
+ window.__gottyZmodemDebug(
30880
+ `ZEOF handler local=${this._file_offset} remote=${t.get_offset()}`,
30881
+ ),
30882
+ this._consume_ZEOF(t),
30883
+ window.__gottyZmodemDebug &&
30884
+ window.__gottyZmodemDebug("ZEOF consumed"),
30395
30885
  (this._next_subpacket_handler = null),
30396
30886
  this._make_promise_for_between_files(),
30397
30887
  e(),
30398
- this._send_ZRINIT());
30888
+ window.__gottyZmodemDebug &&
30889
+ window.__gottyZmodemDebug("accept promise resolved from ZEOF"),
30890
+ this._send_ZRINIT(),
30891
+ window.__gottyZmodemDebug &&
30892
+ window.__gottyZmodemDebug("ZRINIT sent after ZEOF"));
30399
30893
  },
30400
30894
  }));
30401
30895
  },
@@ -30964,28 +31458,78 @@
30964
31458
  s = document.getElementById("terminal");
30965
31459
  if (null !== s) {
30966
31460
  var n;
30967
- n = new r.GoTTYXterm(s);
31461
+ const urlParams = new URLSearchParams(window.location.search);
31462
+ const reconnectToken = urlParams.get("reconnect-token") || "";
31463
+ const startupPrefs = {};
31464
+ if (
31465
+ "undefined" != typeof window &&
31466
+ window.gotty_enable_webgl === true
31467
+ ) {
31468
+ startupPrefs.EnableWebGL = !0;
31469
+ }
31470
+ const fontFamily = urlParams.get("font-family");
31471
+ if (fontFamily) {
31472
+ startupPrefs["font-family"] = fontFamily;
31473
+ }
31474
+ const fontSize = urlParams.get("font-size");
31475
+ if (fontSize) {
31476
+ const parsedFontSize = Number(fontSize);
31477
+ if (Number.isFinite(parsedFontSize) && parsedFontSize > 0) {
31478
+ startupPrefs["font-size"] = parsedFontSize;
31479
+ }
31480
+ }
31481
+ const webgl = urlParams.get("webgl");
31482
+ if (webgl) {
31483
+ const normalizedWebgl = webgl.trim().toLowerCase();
31484
+ if (["on", "true", "1"].includes(normalizedWebgl)) {
31485
+ startupPrefs.EnableWebGL = !0;
31486
+ } else if (["off", "false", "0"].includes(normalizedWebgl)) {
31487
+ delete startupPrefs.EnableWebGL;
31488
+ }
31489
+ }
31490
+ const touchScrollThreshold = urlParams.get("touch-scroll-threshold");
31491
+ if (touchScrollThreshold) {
31492
+ const parsedTouchScrollThreshold = Number(touchScrollThreshold);
31493
+ if (
31494
+ Number.isFinite(parsedTouchScrollThreshold) &&
31495
+ parsedTouchScrollThreshold > 0
31496
+ ) {
31497
+ window.touchScrollThreshold = parsedTouchScrollThreshold;
31498
+ }
31499
+ }
31500
+ urlParams.delete("font-family");
31501
+ urlParams.delete("font-size");
31502
+ urlParams.delete("webgl");
31503
+ urlParams.delete("touch-scroll-threshold");
31504
+ n = new r.GoTTYXterm(s, startupPrefs);
30968
31505
  if ("undefined" != typeof window) {
30969
31506
  window.__gottyTerminal = n;
30970
31507
  }
30971
- const i = "https:" == window.location.protocol,
30972
- o = "" === gotty_ws_query_args ? "" : "?" + gotty_ws_query_args,
30973
- a =
30974
- (i ? "wss://" : "ws://") +
30975
- window.location.host +
30976
- window.location.pathname +
30977
- "ws" +
30978
- o,
30979
- l = window.location.search,
30980
- c = new e.ConnectionFactory(a, t.protocols),
30981
- d = new t.WebTTY(n, c, l, gotty_auth_token);
31508
+ const isHttps = "https:" == window.location.protocol;
31509
+ const wsQuery = "" === gotty_ws_query_args ? "" : "?" + gotty_ws_query_args;
31510
+ const wsUrl =
31511
+ (isHttps ? "wss://" : "ws://") +
31512
+ window.location.host +
31513
+ window.location.pathname +
31514
+ "ws" +
31515
+ wsQuery;
31516
+ urlParams.delete("reconnect-token");
31517
+ const sessionQuery = urlParams.toString();
31518
+ const connectionFactory = new e.ConnectionFactory(wsUrl, t.protocols);
31519
+ const webTTY = new t.WebTTY(
31520
+ n,
31521
+ connectionFactory,
31522
+ "" === sessionQuery ? "" : "?" + sessionQuery,
31523
+ gotty_auth_token,
31524
+ );
31525
+ webTTY.reconnectToken = reconnectToken;
30982
31526
  if ("undefined" != typeof window) {
30983
31527
  window.__gottyXterm = s.__gottyXterm || null;
30984
- window.__gottyWebTTY = d;
31528
+ window.__gottyWebTTY = webTTY;
30985
31529
  }
30986
- const h = d.open();
31530
+ const closeSession = webTTY.open();
30987
31531
  window.addEventListener("unload", () => {
30988
- (h(), n.close());
31532
+ (closeSession(), n.close());
30989
31533
  });
30990
31534
  }
30991
31535
  })();