pirc-extension 0.3.12 → 0.3.14

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pirc-extension",
3
- "version": "0.3.12",
4
- "description": "PiRC: puts every interactive pi session on a PiRC relay",
3
+ "version": "0.3.14",
4
+ "description": "PiRC: remote control for pi from your iPhone, Android phone or browser",
5
5
  "license": "MIT",
6
6
  "homepage": "https://pirc.dev",
7
7
  "repository": {
@@ -1,4 +1,4 @@
1
- // PiRC extension 0.3.12. Third-party code in this file: @bufbuild/protobuf@2.16.0, ws@8.22.0; see NOTICE.
1
+ // PiRC extension 0.3.14. Third-party code in this file: @bufbuild/protobuf@2.16.0, ws@8.22.0; see NOTICE.
2
2
  import { createRequire as __pircCreateRequire } from "node:module";
3
3
  const require = __pircCreateRequire(import.meta.url);
4
4
  var __create = Object.create;
@@ -8195,47 +8195,53 @@ async function tmuxPlace(env) {
8195
8195
  return place({ kind: "tmux", group, window, windowNumber: Number(windowNumber) });
8196
8196
  }
8197
8197
  function herdrSession(path) {
8198
- const socket = createConnection(path);
8199
- let buf = "";
8198
+ const open = /* @__PURE__ */ new Set();
8200
8199
  let n = 0;
8201
- const waiting = /* @__PURE__ */ new Map();
8202
- const failAll = (e) => {
8203
- for (const w of waiting.values()) w.reject(e);
8204
- waiting.clear();
8205
- };
8206
- socket.setEncoding("utf8");
8207
- socket.on("data", (d) => {
8208
- buf += d;
8209
- let i;
8210
- while ((i = buf.indexOf("\n")) >= 0) {
8211
- const line = buf.slice(0, i);
8212
- buf = buf.slice(i + 1);
8213
- let m;
8214
- try {
8215
- m = JSON.parse(line);
8216
- } catch {
8217
- continue;
8218
- }
8219
- const w = m.id ? waiting.get(m.id) : void 0;
8220
- if (!w) continue;
8221
- waiting.delete(m.id);
8222
- if (m.result) w.resolve(m.result);
8223
- else w.reject(new Error(`herdr: ${m.error?.message ?? "no result"}`));
8224
- }
8225
- });
8226
- socket.on("error", (e) => failAll(e));
8227
- socket.on("close", () => failAll(new Error("herdr closed the connection")));
8200
+ let closed = false;
8228
8201
  return {
8229
8202
  ask(method, params) {
8230
8203
  const id = `pirc-${++n}`;
8231
8204
  return new Promise((resolve, reject) => {
8232
- waiting.set(id, { resolve, reject });
8205
+ if (closed) return reject(new Error("herdr did not answer in time"));
8206
+ const socket = createConnection(path);
8207
+ open.add(socket);
8208
+ let buf = "";
8209
+ let done = false;
8210
+ const finish = (err, result) => {
8211
+ if (done) return;
8212
+ done = true;
8213
+ open.delete(socket);
8214
+ socket.destroy();
8215
+ if (err) reject(err);
8216
+ else resolve(result);
8217
+ };
8218
+ socket.setEncoding("utf8");
8219
+ socket.on("data", (d) => {
8220
+ buf += d;
8221
+ let i;
8222
+ while ((i = buf.indexOf("\n")) >= 0) {
8223
+ const line = buf.slice(0, i);
8224
+ buf = buf.slice(i + 1);
8225
+ let m;
8226
+ try {
8227
+ m = JSON.parse(line);
8228
+ } catch {
8229
+ continue;
8230
+ }
8231
+ if (m.id !== id) continue;
8232
+ if (m.result) finish(void 0, m.result);
8233
+ else finish(new Error(`herdr: ${m.error?.message ?? "no result"}`));
8234
+ }
8235
+ });
8236
+ socket.on("error", (e) => finish(new Error(`herdr: ${e.message}`)));
8237
+ socket.on("close", () => finish(new Error(closed ? "herdr did not answer in time" : "herdr closed the connection")));
8233
8238
  socket.write(`${JSON.stringify({ id, method, params })}
8234
8239
  `);
8235
8240
  });
8236
8241
  },
8237
8242
  close() {
8238
- socket.destroy();
8243
+ closed = true;
8244
+ for (const s of open) s.destroy();
8239
8245
  }
8240
8246
  };
8241
8247
  }
@@ -10056,8 +10062,8 @@ var Host = class _Host {
10056
10062
  };
10057
10063
 
10058
10064
  // extension/src/index.ts
10059
- var EXTENSION_VERSION = true ? "0.3.12" : "dev";
10060
- var LOAD = true ? "0.3.12" : `dev ${randomBytes4(4).toString("hex")}`;
10065
+ var EXTENSION_VERSION = true ? "0.3.14" : "dev";
10066
+ var LOAD = true ? "0.3.14" : `dev ${randomBytes4(4).toString("hex")}`;
10061
10067
  var KEY = /* @__PURE__ */ Symbol.for("pirc.extension");
10062
10068
  var proc = globalThis[KEY] ??= {};
10063
10069
  var USAGE = HOSTED ? "usage: /pirc [status | enrol <relay-url> [token] | join <hosted-relay> | leave | reconnect]" : "usage: /pirc [status | enrol <relay-url> [token] | reconnect]";
File without changes
File without changes