@decentnetwork/beagle 0.1.148 → 0.1.153

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,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.148";
1
+ window.__DK_UI_VERSION="0.1.153";
2
2
  "use strict";
3
3
  (() => {
4
4
  // packages/beagle-ui/dist/beagle-ui.js
@@ -2109,6 +2109,10 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2109
2109
  };
2110
2110
  try {
2111
2111
  const r = await it.sender(it.file, onProgress);
2112
+ if (r && r.rtcFailed) {
2113
+ it.rtcFailed = true;
2114
+ it.rtcError = r.rtcError ? String(r.rtcError) : null;
2115
+ }
2112
2116
  if (r && r.ok === false) {
2113
2117
  it.status = "failed";
2114
2118
  it.error = r.error && String(r.error) || "send failed";
@@ -2166,16 +2170,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2166
2170
  }
2167
2171
  };
2168
2172
  }
2169
- function failureReport(done, lang) {
2170
- const failed = (done || []).filter((x) => x.status === "failed");
2171
- if (!failed.length)
2172
- return null;
2173
- const zh = lang === "zh";
2174
- if (done.length === 1)
2175
- return (zh ? "\u53D1\u9001\u5931\u8D25: " : "Send failed: ") + (failed[0].error || "");
2176
- const head = zh ? `${done.length} \u4E2A\u6587\u4EF6\u4E2D\u6709 ${failed.length} \u4E2A\u6CA1\u6709\u53D1\u9001:` : `${failed.length} of ${done.length} files did not send:`;
2177
- return head + "\n\n" + failed.map((x) => `\u2022 ${x.name} \u2014 ${x.error || (zh ? "\u53D1\u9001\u5931\u8D25" : "send failed")}`).join("\n");
2178
- }
2179
2173
  function successFlash(done, lang) {
2180
2174
  const n = (done || []).length;
2181
2175
  const zh = lang === "zh";
@@ -2184,6 +2178,31 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2184
2178
  return rtc ? zh ? "WebRTC \u6587\u4EF6\u53D1\u9001\u5B8C\u6210" : "WebRTC file sent" : zh ? "\u6587\u4EF6\u5DF2\u63D0\u4EA4\u53D1\u9001" : "File send started";
2185
2179
  return rtc ? zh ? `\u5DF2\u901A\u8FC7 WebRTC \u53D1\u9001 ${n} \u4E2A\u6587\u4EF6` : `${n} files sent via WebRTC` : zh ? `\u5DF2\u63D0\u4EA4\u53D1\u9001 ${n} \u4E2A\u6587\u4EF6` : `${n} file sends started`;
2186
2180
  }
2181
+ function keptResults(done) {
2182
+ return (done || []).filter((x) => x.status === "failed" || x.rtcFailed);
2183
+ }
2184
+ function resultLabel(it, lang) {
2185
+ const zh = lang === "zh";
2186
+ const name = (it.via === "webrtc" ? "WebRTC \xB7 " : "") + (it.name || "file");
2187
+ if (it.status === "failed") {
2188
+ const why = it.error || (zh ? "\u53D1\u9001\u5931\u8D25" : "send failed");
2189
+ if (it.rtcFailed)
2190
+ return name + (zh ? " \xB7 \u5931\u8D25(WebRTC \u4E0E Carrier \u5747\u672A\u6210\u529F): " : " \xB7 failed (WebRTC, then Carrier): ") + why;
2191
+ return name + (zh ? " \xB7 \u5931\u8D25: " : " \xB7 failed: ") + why;
2192
+ }
2193
+ return name + (zh ? " \xB7 WebRTC \u5931\u8D25 \u2014 \u5DF2\u901A\u8FC7 Carrier \u53D1\u9001" : " \xB7 WebRTC failed \u2014 sent via Carrier");
2194
+ }
2195
+ function finishFlash(done, lang) {
2196
+ const zh = lang === "zh";
2197
+ const failed = (done || []).filter((x) => x.status === "failed").length;
2198
+ if (failed) {
2199
+ const n = (done || []).length;
2200
+ return ["err", n === 1 ? zh ? "\u53D1\u9001\u5931\u8D25,\u89C1\u4E0B\u65B9" : "Send failed \u2014 see below" : zh ? `${n} \u4E2A\u6587\u4EF6\u4E2D\u6709 ${failed} \u4E2A\u6CA1\u6709\u53D1\u9001,\u89C1\u4E0B\u65B9` : `${failed} of ${n} files did not send \u2014 see below`];
2201
+ }
2202
+ if ((done || []).some((x) => x.rtcFailed))
2203
+ return ["ok", zh ? "WebRTC \u5931\u8D25,\u5DF2\u901A\u8FC7 Carrier \u53D1\u9001" : "WebRTC failed \u2014 sent via Carrier"];
2204
+ return ["ok", successFlash(done, lang)];
2205
+ }
2187
2206
  var PROOF_KEY = { eth: "proof.eth", sol: "proof.sol" };
2188
2207
  var HEAD = "Beagle wallet binding";
2189
2208
  var LINE = "I bind this wallet to my Beagle identity.";
@@ -4539,6 +4558,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
4539
4558
  };
4540
4559
  const [dragOver, setDragOver] = React.useState(false);
4541
4560
  const [sending, setSending] = React.useState(null);
4561
+ const [sendResults, setSendResults] = React.useState([]);
4542
4562
  const [theater, setTheater] = React.useState(null);
4543
4563
  React.useEffect(() => {
4544
4564
  setDraft("");
@@ -4567,11 +4587,11 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
4567
4587
  };
4568
4588
  const finishRef = React.useRef(null);
4569
4589
  finishRef.current = (done) => {
4570
- const report = failureReport(done, lang);
4571
- if (report)
4572
- window.alert(report);
4573
- else
4574
- showFlash("ok", successFlash(done, lang));
4590
+ const kept = keptResults(done);
4591
+ if (kept.length)
4592
+ setSendResults((prev) => prev.concat(kept).slice(-20));
4593
+ const [kind, msg] = finishFlash(done, lang);
4594
+ showFlash(kind, msg);
4575
4595
  requestAnimationFrame(scrollToBottom);
4576
4596
  };
4577
4597
  const queueRef = React.useRef(null);
@@ -4589,6 +4609,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
4589
4609
  queueRef.current.add(files, sender, { via: mode, peerId: peer.id });
4590
4610
  };
4591
4611
  const mySending = sending ? sending.filter((s) => s.peerId === peer.id) : [];
4612
+ const myResults = sendResults.filter((s) => s.peerId === peer.id);
4613
+ const dismissResults = () => setSendResults((prev) => prev.filter((s) => s.peerId !== peer.id));
4592
4614
  const onDrop = (e) => {
4593
4615
  e.preventDefault();
4594
4616
  setDragOver(false);
@@ -4750,7 +4772,7 @@ ${peer.address}`
4750
4772
  stroke: 2.2,
4751
4773
  color: flash.kind === "err" ? "var(--danger)" : "var(--accent)"
4752
4774
  }
4753
- ), flash.msg), mySending.length > 0 && /* @__PURE__ */ React.createElement("div", { "data-testid": "file-send-queue", style: { maxWidth: 1200, margin: "0 auto 8px", display: "flex", flexDirection: "column", gap: 3, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--faint)", maxHeight: 132, overflowY: "auto" } }, mySending.length > 1 && /* @__PURE__ */ React.createElement("div", { style: { color: "var(--dim)" } }, (lang === "zh" ? "\u53D1\u9001 " : "Sending ") + mySending.filter((s) => s.status === "sent" || s.status === "failed").length + " / " + mySending.length + (lang === "zh" ? " \u4E2A\u6587\u4EF6" : " files")), mySending.map((s) => /* @__PURE__ */ React.createElement("div", { key: s.id, "data-status": s.status, style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0, color: s.status === "failed" ? "var(--danger)" : void 0 } }, /* @__PURE__ */ React.createElement(
4775
+ ), flash.msg), (mySending.length > 0 || myResults.length > 0) && /* @__PURE__ */ React.createElement("div", { "data-testid": "file-send-queue", style: { maxWidth: 1200, margin: "0 auto 8px", display: "flex", flexDirection: "column", gap: 3, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--faint)", maxHeight: 132, overflowY: "auto" } }, mySending.length > 1 && /* @__PURE__ */ React.createElement("div", { style: { color: "var(--dim)" } }, (lang === "zh" ? "\u53D1\u9001 " : "Sending ") + mySending.filter((s) => s.status === "sent" || s.status === "failed").length + " / " + mySending.length + (lang === "zh" ? " \u4E2A\u6587\u4EF6" : " files")), mySending.map((s) => /* @__PURE__ */ React.createElement("div", { key: s.id, "data-status": s.status, style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0, color: s.status === "failed" ? "var(--danger)" : void 0 } }, /* @__PURE__ */ React.createElement(
4754
4776
  Icon,
4755
4777
  {
4756
4778
  name: s.status === "sent" ? "check" : s.status === "failed" ? "x" : "paperclip",
@@ -4758,7 +4780,37 @@ ${peer.address}`
4758
4780
  stroke: 2,
4759
4781
  color: s.status === "failed" ? "var(--danger)" : s.status === "waiting" ? "var(--faint)" : "var(--accent)"
4760
4782
  }
4761
- ), /* @__PURE__ */ React.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 } }, (s.status === "sending" ? lang === "zh" ? "\u53D1\u9001\u4E2D: " : "Sending: " : "") + (s.via === "webrtc" ? "WebRTC \xB7 " : "") + s.name + (s.status === "sending" ? (s.size ? " \xB7 " + dkFileSize(s.sent || 0) + " / " + dkFileSize(s.size) : "") + (s.pct != null ? " \xB7 " + Math.min(100, Math.max(0, s.pct)).toFixed(1) + "%" : "") + (s.kbps != null ? " \xB7 " + dkSpeed(s.kbps) : "") : s.status === "waiting" ? " \xB7 " + (s.size ? dkFileSize(s.size) + " \xB7 " : "") + (lang === "zh" ? "\u7B49\u5F85\u4E2D" : "waiting") : s.status === "failed" ? " \xB7 " + (s.error || "") : " \xB7 " + (lang === "zh" ? "\u5DF2\u63D0\u4EA4" : "done")))))), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex", alignItems: "center", gap: phone ? 6 : 10 } }, /* @__PURE__ */ React.createElement(
4783
+ ), /* @__PURE__ */ React.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 } }, (s.status === "sending" ? lang === "zh" ? "\u53D1\u9001\u4E2D: " : "Sending: " : "") + (s.via === "webrtc" ? "WebRTC \xB7 " : "") + s.name + (s.status === "sending" ? (s.size ? " \xB7 " + dkFileSize(s.sent || 0) + " / " + dkFileSize(s.size) : "") + (s.pct != null ? " \xB7 " + Math.min(100, Math.max(0, s.pct)).toFixed(1) + "%" : "") + (s.kbps != null ? " \xB7 " + dkSpeed(s.kbps) : "") : s.status === "waiting" ? " \xB7 " + (s.size ? dkFileSize(s.size) + " \xB7 " : "") + (lang === "zh" ? "\u7B49\u5F85\u4E2D" : "waiting") : s.status === "failed" ? " \xB7 " + (s.error || "") : " \xB7 " + (lang === "zh" ? "\u5DF2\u63D0\u4EA4" : "done"))))), myResults.map((s, i) => /* @__PURE__ */ React.createElement(
4784
+ "div",
4785
+ {
4786
+ key: "r" + s.id,
4787
+ "data-testid": "file-send-result",
4788
+ "data-status": s.status,
4789
+ "data-rtc-failed": s.rtcFailed ? "1" : void 0,
4790
+ title: s.rtcError ? "WebRTC: " + s.rtcError : void 0,
4791
+ style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0, color: s.status === "failed" ? "var(--danger)" : "var(--dim)" }
4792
+ },
4793
+ /* @__PURE__ */ React.createElement(
4794
+ Icon,
4795
+ {
4796
+ name: s.status === "failed" ? "x" : "check",
4797
+ size: 13,
4798
+ stroke: 2,
4799
+ color: s.status === "failed" ? "var(--danger)" : "var(--faint)"
4800
+ }
4801
+ ),
4802
+ /* @__PURE__ */ React.createElement("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 } }, resultLabel(s, lang)),
4803
+ i === myResults.length - 1 && /* @__PURE__ */ React.createElement(
4804
+ "button",
4805
+ {
4806
+ onClick: dismissResults,
4807
+ title: lang === "zh" ? "\u5173\u95ED" : "Dismiss",
4808
+ "aria-label": lang === "zh" ? "\u5173\u95ED" : "Dismiss",
4809
+ style: { flexShrink: 0, border: "none", background: "transparent", color: "var(--faint)", cursor: "pointer", padding: "0 2px", fontFamily: "var(--mono)", fontSize: 11.5 }
4810
+ },
4811
+ lang === "zh" ? "\u5173\u95ED" : "dismiss"
4812
+ )
4813
+ ))), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex", alignItems: "center", gap: phone ? 6 : 10 } }, /* @__PURE__ */ React.createElement(
4762
4814
  "input",
4763
4815
  {
4764
4816
  ref: fileRef,
@@ -4909,7 +4961,7 @@ ${peer.address}`
4909
4961
  style: { maxWidth: "100%", maxHeight: "100%", objectFit: "contain", borderRadius: 6 }
4910
4962
  }
4911
4963
  ))),
4912
- pubProfile && /* @__PURE__ */ React.createElement(DkPublicProfile, { T, userid: peer.userId, fallbackName: verifiedLabel(peer.userId, peer.alias), isFriend: true, onClose: () => setPubProfile(false) }),
4964
+ pubProfile && /* @__PURE__ */ React.createElement(DkPublicProfile, { T, userid: peer.userId, fallbackName: verifiedLabel(peer.userId, peer.alias), isFriend: true, friend: peer, onClose: () => setPubProfile(false) }),
4913
4965
  nameCardProf && (() => {
4914
4966
  const cardFriend2 = cardFriend(nameCardProf, peers);
4915
4967
  return /* @__PURE__ */ React.createElement(
@@ -4960,6 +5012,75 @@ ${peer.address}`
4960
5012
  return /* @__PURE__ */ React.createElement("div", { style: { flex: 1, display: "flex", minWidth: 0, minHeight: 0 } }, /* @__PURE__ */ React.createElement(PeerSidebar, { T, peers, requests, activeId, onSelect, onAct, onAdd, prefillAddr, onPrefillConsumed, muted, isProtocol, protocolFix }), peer ? /* @__PURE__ */ React.createElement(Conversation, { T, peer, lang, peers, onOpenChat: onSelect, thread, isProtocol, onSend, onSendFile, onSendRtcFile, onAlias, onRemove, onOpenNet, onCall, onReloadThread, hasEarlier, onLoadEarlier, onAssistantRemove, onAssistantAdopt, muted: !!muted && muted.includes(peer.id), onToggleMute }) : /* @__PURE__ */ React.createElement(ChatEmpty, { T }));
4961
5013
  }
4962
5014
  Object.assign(window, { ChatTab });
5015
+ var PLATFORM = { ios: "iOS", android: "Android", darwin: "macOS", macos: "macOS", linux: "Linux", win32: "Windows", windows: "Windows", js: "Browser", browser: "Browser", web: "Browser", agent: "Agent" };
5016
+ var clean2 = (v) => typeof v === "string" && v.trim() ? v.trim() : "";
5017
+ function platformLabel(p) {
5018
+ const v = clean2(p);
5019
+ if (!v)
5020
+ return "";
5021
+ return Object.prototype.hasOwnProperty.call(PLATFORM, v.toLowerCase()) ? PLATFORM[v.toLowerCase()] : v;
5022
+ }
5023
+ function osVersionLabel(v) {
5024
+ const s = clean2(v);
5025
+ return !s || /^[a-z]+-?$/i.test(s) ? "" : s;
5026
+ }
5027
+ function rspLabel(protocol, notAdvertised) {
5028
+ if (typeof protocol !== "string")
5029
+ return "";
5030
+ return protocol ? protocol.toUpperCase() : notAdvertised || "Not advertised";
5031
+ }
5032
+ var LINK_BASE = { twitter: "https://x.com/", linkedin: "https://www.linkedin.com/in/", github: "https://github.com/" };
5033
+ var shortDate = (ms) => {
5034
+ try {
5035
+ return new Date(ms).toLocaleString(void 0, { dateStyle: "medium", timeStyle: "short" });
5036
+ } catch (e) {
5037
+ return new Date(ms).toLocaleString();
5038
+ }
5039
+ };
5040
+ function friendCardView(friend, prof, T = {}, fmtDate2 = shortDate) {
5041
+ const f = friend || {};
5042
+ const p = prof || {};
5043
+ const name = clean2(p.displayName) || clean2(f.alias) || clean2(f.name);
5044
+ const ens = clean2(p.ens) || clean2(f.ensClaim) || clean2(f.ens);
5045
+ const description = clean2(p.description) || clean2(f.description);
5046
+ const avatarUrl = clean2(p.avatarUrl) || clean2(f.avatarUrl) || clean2(f.pushedAvatarUrl);
5047
+ const punkId = p.punkId != null ? p.punkId : f.punkId != null ? f.punkId : null;
5048
+ const userid = f.userId || f.id || "";
5049
+ const address = clean2(f.address) || clean2(p.address);
5050
+ const rows = [];
5051
+ if (friend) {
5052
+ const status = f.online ? T.statusOnline || "Online" : (T.statusOffline || "Offline") + (f.lastSessionAt ? " \xB7 " + (T.lastSeen || "last seen") + " " + fmtDate2(f.lastSessionAt) : "");
5053
+ rows.push({ key: "status", label: T.status || "Status", value: status, online: !!f.online });
5054
+ }
5055
+ if (clean2(p.eth))
5056
+ rows.push({ key: "eth", label: "ethereum", value: p.eth, copy: true, head: 8 });
5057
+ if (clean2(p.sol))
5058
+ rows.push({ key: "sol", label: "solana", value: p.sol, copy: true, head: 8 });
5059
+ if (userid)
5060
+ rows.push({ key: "userid", label: T.userId || "user id", value: userid, copy: true, head: 10 });
5061
+ if (address && address !== userid)
5062
+ rows.push({ key: "address", label: T.addr || "address", value: address, copy: true, head: 8 });
5063
+ const links = Object.entries(p.links || {}).filter(([, h]) => clean2(h)).map(([k, h]) => ({ key: k, label: k, href: (LINK_BASE[k] || "") + h }));
5064
+ const site = clean2(f.profileUrl);
5065
+ if (site && !links.some((l) => l.href === site))
5066
+ links.push({ key: "website", label: T.website || "website", href: site });
5067
+ const client = [];
5068
+ if (friend) {
5069
+ const plat = platformLabel(f.platform);
5070
+ if (plat)
5071
+ client.push({ key: "platform", label: T.friendPlatform || "Platform", value: plat });
5072
+ const os = osVersionLabel(f.osVersion);
5073
+ if (os)
5074
+ client.push({ key: "os", label: T.friendOsVersion || "OS version", value: os });
5075
+ const app = clean2(f.appVersion);
5076
+ if (app)
5077
+ client.push({ key: "app", label: T.friendAppVersion || "App version", value: app });
5078
+ const rsp = rspLabel(f.rspProtocol, T.friendRspNotAdvertised);
5079
+ if (rsp)
5080
+ client.push({ key: "rsp", label: "RSP", value: rsp });
5081
+ }
5082
+ return { name, ens, description, avatarUrl, punkId, userid, address, rows, links, client };
5083
+ }
4963
5084
  function CopyBtn({ value, copiedText = "Copied", copyFailedText = "Copy failed", copyTitle = "Copy" }) {
4964
5085
  const [status, setStatus] = React.useState(null);
4965
5086
  const timer = React.useRef(null);
@@ -5236,7 +5357,7 @@ ${peer.address}`
5236
5357
  function DkPublicProfile({ T, userid, fallbackName, onClose, isFriend, isMe, onMessage, card, friend }) {
5237
5358
  const view = card ? nameCardView(card, friend ? [friend] : []) : null;
5238
5359
  const [st, setSt] = React.useState({ loading: true });
5239
- const ensV = useEnsVerdict(userid, st.prof && st.prof.ens);
5360
+ const ensV = useEnsVerdict(userid, st.prof && st.prof.ens || friend && (friend.ensClaim || friend.ens) || "");
5240
5361
  const [addState, setAddState] = React.useState(null);
5241
5362
  const [recOpen, setRecOpen] = React.useState(false);
5242
5363
  const [recPeers, setRecPeers] = React.useState(null);
@@ -5252,13 +5373,14 @@ ${peer.address}`
5252
5373
  };
5253
5374
  const recommendTo = (p) => {
5254
5375
  const prof2 = st.prof || {};
5376
+ const fc = friend ? friendCardView(friend, st.prof, T) : null;
5255
5377
  const text = dkEncodeBeagleContact({
5256
- name: prof2.displayName || fallbackName || "",
5257
- ens: prof2.ens || "",
5378
+ name: fc && fc.name || prof2.displayName || fallbackName || "",
5379
+ ens: fc && fc.ens || prof2.ens || "",
5258
5380
  userid,
5259
- address: prof2.address || "",
5260
- avatar: prof2.avatarUrl || "",
5261
- description: prof2.description || ""
5381
+ address: fc && fc.address || prof2.address || "",
5382
+ avatar: fc && fc.avatarUrl || prof2.avatarUrl || "",
5383
+ description: fc && fc.description || prof2.description || ""
5262
5384
  });
5263
5385
  setRecState((s) => ({ ...s, [p.id]: "busy" }));
5264
5386
  fetch("/api/chat-send", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ userid: p.userId, text }) }).then((r) => r.json()).then((r) => setRecState((s) => ({ ...s, [p.id]: r.ok !== false ? "sent" : r.error || "failed" }))).catch((e) => setRecState((s) => ({ ...s, [p.id]: String(e && e.message || e) })));
@@ -5282,17 +5404,20 @@ ${peer.address}`
5282
5404
  };
5283
5405
  }, [userid]);
5284
5406
  const prof = st.prof;
5285
- const LINK_BASE = { twitter: "https://x.com/", linkedin: "https://www.linkedin.com/in/", github: "https://github.com/" };
5286
- const links = prof ? Object.entries(prof.links || {}) : [];
5407
+ const fv = isFriend && friend ? friendCardView(friend, prof, T) : null;
5408
+ const pv = prof || {};
5409
+ const LINK_BASE2 = { twitter: "https://x.com/", linkedin: "https://www.linkedin.com/in/", github: "https://github.com/" };
5410
+ const links = fv ? fv.links.map((l) => [l.label, l.href, true]) : prof ? Object.entries(prof.links || {}) : [];
5411
+ const cardAddress = fv ? fv.address : pv.address;
5287
5412
  const lbl = { width: 110, flexShrink: 0, fontFamily: "var(--mono)", fontSize: 11, fontWeight: 600, color: "var(--faint)", textTransform: "uppercase", letterSpacing: 0.5 };
5288
5413
  const rowS = { display: "flex", alignItems: "center", gap: 10, padding: "10px 0", borderTop: "1px solid var(--line)" };
5289
- return /* @__PURE__ */ React.createElement("div", { onClick: onClose, style: { position: "fixed", inset: 0, zIndex: 90, background: "color-mix(in oklab, #000, transparent 38%)", display: "flex", alignItems: "center", justifyContent: "center", padding: 24 } }, /* @__PURE__ */ React.createElement("div", { onClick: (e) => e.stopPropagation(), style: { width: 420, maxWidth: "94vw", background: "var(--panel)", border: "1px solid var(--line)", borderRadius: 16, padding: "20px 22px", display: "flex", flexDirection: "column", gap: 14 } }, /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 14 } }, prof && prof.avatarUrl ? /* @__PURE__ */ React.createElement(DkImgAvatar, { url: prof.avatarUrl, seed: userid, size: 56, radius: 14 }) : prof && prof.punkId != null ? /* @__PURE__ */ React.createElement(DkPunkAvatar, { id: prof.punkId, size: 56, radius: 14, fallbackSeed: userid }) : friend ? /* @__PURE__ */ React.createElement(DkAvatar, { peer: friend, size: 56, radius: 14, dot: false }) : card && card.avatar ? /* @__PURE__ */ React.createElement(DkImgAvatar, { url: card.avatar, seed: userid, size: 56, radius: 14 }) : /* @__PURE__ */ React.createElement(DkIdenticon, { seed: userid, size: 56, radius: 14 }), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, minWidth: 0 } }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 17, fontWeight: 700, color: "var(--text)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, prof && prof.displayName || fallbackName || shortKey(userid, 10, 6)), prof && prof.ens && /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5, fontFamily: "var(--mono)", fontSize: 12, color: "var(--accent)", marginTop: 2 } }, prof.ens, /* @__PURE__ */ React.createElement(DkEnsMark, { verdict: ensV, T }))), /* @__PURE__ */ React.createElement(Btn, { icon: "x", size: "sm", onClick: onClose })), st.loading ? /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)" } }, T.dirLoading || "loading\u2026") : !prof && view ? /* @__PURE__ */ React.createElement(DkNameCardNoProfile, { T, view, card, onMessage, isMe }) : !prof ? /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)" } }, T.pubNone || "No public profile \u2014 this user has not registered a beagles.eth name.") : /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column" } }, prof.description && /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--dim)", paddingBottom: 12, lineHeight: 1.5 } }, prof.description), links.length > 0 && // Label keeps its column; pills wrap inside their OWN container so
5414
+ return /* @__PURE__ */ React.createElement("div", { onClick: onClose, style: { position: "fixed", inset: 0, zIndex: 90, background: "color-mix(in oklab, #000, transparent 38%)", display: "flex", alignItems: "center", justifyContent: "center", padding: 24 } }, /* @__PURE__ */ React.createElement("div", { onClick: (e) => e.stopPropagation(), style: { width: 420, maxWidth: "94vw", maxHeight: "calc(100dvh - 48px)", overflowY: "auto", background: "var(--panel)", border: "1px solid var(--line)", borderRadius: 16, padding: "20px 22px", display: "flex", flexDirection: "column", gap: 14 } }, /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 14 } }, prof && prof.avatarUrl ? /* @__PURE__ */ React.createElement(DkImgAvatar, { url: prof.avatarUrl, seed: userid, size: 56, radius: 14 }) : prof && prof.punkId != null ? /* @__PURE__ */ React.createElement(DkPunkAvatar, { id: prof.punkId, size: 56, radius: 14, fallbackSeed: userid }) : fv && fv.avatarUrl ? /* @__PURE__ */ React.createElement(DkImgAvatar, { url: fv.avatarUrl, seed: userid, size: 56, radius: 14 }) : friend ? /* @__PURE__ */ React.createElement(DkAvatar, { peer: friend, size: 56, radius: 14, dot: false }) : card && card.avatar ? /* @__PURE__ */ React.createElement(DkImgAvatar, { url: card.avatar, seed: userid, size: 56, radius: 14 }) : /* @__PURE__ */ React.createElement(DkIdenticon, { seed: userid, size: 56, radius: 14 }), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, minWidth: 0 } }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 17, fontWeight: 700, color: "var(--text)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, fv && fv.name || prof && prof.displayName || fallbackName || shortKey(userid, 10, 6)), (fv ? fv.ens : prof && prof.ens) && /* @__PURE__ */ React.createElement("div", { "data-testid": "friend-card-ens", style: { display: "flex", alignItems: "center", gap: 5, fontFamily: "var(--mono)", fontSize: 12, color: "var(--accent)", marginTop: 2 } }, fv ? fv.ens : prof.ens, /* @__PURE__ */ React.createElement(DkEnsMark, { verdict: ensV, T }))), /* @__PURE__ */ React.createElement(Btn, { icon: "x", size: "sm", onClick: onClose })), st.loading && !fv ? /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)" } }, T.dirLoading || "loading\u2026") : !prof && !fv && view ? /* @__PURE__ */ React.createElement(DkNameCardNoProfile, { T, view, card, onMessage, isMe }) : !prof && !fv ? /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)" } }, T.pubNone || "No public profile \u2014 this user has not registered a beagles.eth name.") : /* @__PURE__ */ React.createElement("div", { "data-testid": fv ? "friend-card" : void 0, style: { display: "flex", flexDirection: "column" } }, (fv ? fv.description : pv.description) && /* @__PURE__ */ React.createElement("div", { "data-testid": "friend-card-bio", style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--dim)", paddingBottom: 12, lineHeight: 1.5, overflowWrap: "anywhere" } }, fv ? fv.description : pv.description), links.length > 0 && // Label keeps its column; pills wrap inside their OWN container so
5290
5415
  // an overflowing pill lands under the first pill, never under the label.
5291
- /* @__PURE__ */ React.createElement("div", { style: { ...rowS, alignItems: "flex-start" } }, /* @__PURE__ */ React.createElement("span", { style: { ...lbl, paddingTop: 5 } }, T.linksCard || "links"), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, minWidth: 0, display: "flex", gap: 8, flexWrap: "wrap" } }, links.map(([k, h]) => /* @__PURE__ */ React.createElement(
5416
+ /* @__PURE__ */ React.createElement("div", { style: { ...rowS, alignItems: "flex-start" } }, /* @__PURE__ */ React.createElement("span", { style: { ...lbl, paddingTop: 5 } }, T.linksCard || "links"), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, minWidth: 0, display: "flex", gap: 8, flexWrap: "wrap" } }, links.map(([k, h, full]) => /* @__PURE__ */ React.createElement(
5292
5417
  "a",
5293
5418
  {
5294
5419
  key: k,
5295
- href: (LINK_BASE[k] || "") + h,
5420
+ href: full ? h : (LINK_BASE2[k] || "") + h,
5296
5421
  target: "_blank",
5297
5422
  rel: "noreferrer",
5298
5423
  style: { display: "inline-flex", alignItems: "center", gap: 5, padding: "4px 10px", borderRadius: 999, border: "1px solid var(--line)", textDecoration: "none", fontFamily: "var(--ui)", fontSize: 12, color: "var(--accent)" }
@@ -5301,10 +5426,13 @@ ${peer.address}`
5301
5426
  " \u2197"
5302
5427
  )))), (() => {
5303
5428
  const kvRow = (label, value, head = 8) => /* @__PURE__ */ React.createElement("div", { style: rowS, key: label }, /* @__PURE__ */ React.createElement("span", { style: lbl }, label), /* @__PURE__ */ React.createElement("span", { title: value, style: { flex: 1, minWidth: 0, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--dim)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, shortKey(value, head, 6)), /* @__PURE__ */ React.createElement(CopyBtn, { value, copiedText: T.copied, copyFailedText: T.copyFailed, copyTitle: T.copy }));
5429
+ if (fv) {
5430
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, fv.rows.map((r) => r.copy ? kvRow(r.label, r.value, r.head) : /* @__PURE__ */ React.createElement("div", { style: rowS, key: r.key, "data-testid": "friend-card-" + r.key }, /* @__PURE__ */ React.createElement("span", { style: lbl }, r.label), /* @__PURE__ */ React.createElement("span", { style: { flex: 1, minWidth: 0, display: "inline-flex", alignItems: "center", gap: 6, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--dim)" } }, r.key === "status" && /* @__PURE__ */ React.createElement("span", { style: { width: 7, height: 7, borderRadius: 999, flexShrink: 0, background: r.online ? "var(--online)" : "var(--faint)" } }), r.value))));
5431
+ }
5304
5432
  return /* @__PURE__ */ React.createElement(React.Fragment, null, prof.eth && kvRow("ethereum", prof.eth), prof.sol && kvRow("solana", prof.sol), kvRow(T.userId || "user id", userid, 10), prof.address && kvRow(T.addr || "address", prof.address));
5305
5433
  })(), (() => {
5306
5434
  const cta = { padding: "7px 16px", borderRadius: 9, cursor: "pointer", fontFamily: "var(--ui)", fontSize: 12.5 };
5307
- return /* @__PURE__ */ React.createElement("div", { style: { ...rowS, justifyContent: "flex-end", gap: 8 } }, !isMe && prof.address && /* @__PURE__ */ React.createElement(
5435
+ return /* @__PURE__ */ React.createElement("div", { style: { ...rowS, justifyContent: "flex-end", gap: 8 } }, !isMe && cardAddress && /* @__PURE__ */ React.createElement(
5308
5436
  "button",
5309
5437
  {
5310
5438
  onClick: openRecommend,
@@ -5318,10 +5446,10 @@ ${peer.address}`
5318
5446
  style: { ...cta, border: "none", background: "var(--accent)", color: "#fff" }
5319
5447
  },
5320
5448
  T.pubMessage || "Message"
5321
- ), !isMe && !isFriend && prof.address && (addState === "sent" ? /* @__PURE__ */ React.createElement(Tag, { tone: "accent" }, T.dirSent || "requested") : addState && addState !== "busy" ? /* @__PURE__ */ React.createElement("span", { title: addState, style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--warn, #f59e0b)" } }, T.addFailed || "failed") : /* @__PURE__ */ React.createElement(
5449
+ ), !isMe && !isFriend && pv.address && (addState === "sent" ? /* @__PURE__ */ React.createElement(Tag, { tone: "accent" }, T.dirSent || "requested") : addState && addState !== "busy" ? /* @__PURE__ */ React.createElement("span", { title: addState, style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--warn, #f59e0b)" } }, T.addFailed || "failed") : /* @__PURE__ */ React.createElement(
5322
5450
  "button",
5323
5451
  {
5324
- onClick: () => addFriend(prof.address),
5452
+ onClick: () => addFriend(pv.address),
5325
5453
  disabled: addState === "busy",
5326
5454
  style: { ...cta, border: "none", background: "var(--accent)", color: "#fff", opacity: addState === "busy" ? 0.6 : 1 }
5327
5455
  },
@@ -5337,7 +5465,7 @@ ${peer.address}`
5337
5465
  /* @__PURE__ */ React.createElement(DkAvatar, { peer: p, size: 26, radius: 7, dot: false }),
5338
5466
  /* @__PURE__ */ React.createElement("span", { style: { flex: 1, minWidth: 0, fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--text)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, /* @__PURE__ */ React.createElement(DkVerifiedName, { userid: p.userId, name: p.alias, fallback: shortKey(p.userId, 8, 6), T })),
5339
5467
  recState[p.id] === "sent" ? /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--online)" } }, T.pubRecSent || "sent \u2713") : recState[p.id] === "busy" ? /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--faint)" } }, "\u2026") : recState[p.id] ? /* @__PURE__ */ React.createElement("span", { title: recState[p.id], style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--warn, #f59e0b)" } }, T.addFailed || "failed") : /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--accent)" } }, T.send || "Send")
5340
- ))))));
5468
+ ))), fv && fv.client.length > 0 && /* @__PURE__ */ React.createElement("div", { "data-testid": "friend-card-client" }, fv.client.map((r) => /* @__PURE__ */ React.createElement("div", { key: r.key, style: rowS, "data-testid": "friend-card-" + r.key }, /* @__PURE__ */ React.createElement("span", { style: lbl }, r.label), /* @__PURE__ */ React.createElement("span", { title: r.value, style: { flex: 1, minWidth: 0, color: "var(--dim)", fontFamily: "var(--mono)", fontSize: 11.5, overflowWrap: "anywhere" } }, r.value)))))));
5341
5469
  }
5342
5470
  function dkAvatarDataUrl(file) {
5343
5471
  return new Promise((resolve, reject) => {
@@ -6215,6 +6343,8 @@ ${peer.address}`
6215
6343
  justifyContent: "center"
6216
6344
  } }, /* @__PURE__ */ React.createElement(Icon, { name: app.icon, size: 19, color: "var(--accent)", stroke: 1.8 })), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, minWidth: 0 } }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 14, fontWeight: 600, color: "var(--text)" } }, pickText(app.name, t && t.lang, app.id)), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)", marginTop: 2 } }, pickText(app.blurb, t && t.lang, "")), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 11, color: "var(--dim)", marginTop: 3 } }, app.host ? zh ? "\u672C\u673A\u5E94\u7528" : "runs in this app" : String(app.origin || "").replace(/^https?:\/\//, ""))), /* @__PURE__ */ React.createElement(Btn, { tone: "accent", size: "sm", onClick: busy ? void 0 : () => open(app) }, busy === app.id ? zh ? "\u6253\u5F00\u4E2D\u2026" : "opening\u2026" : zh ? "\u6253\u5F00" : "Open")))));
6217
6345
  }
6346
+ var DK_Z_CALL_OVERLAY = 1e3;
6347
+ var DK_Z_INCOMING_CALL = 1010;
6218
6348
  var CLAIM_SUPPRESS_MS = 5 * 6e4;
6219
6349
  function newPageId() {
6220
6350
  return "p" + Math.random().toString(36).slice(2, 10) + Date.now().toString(36).slice(-4);
@@ -6254,9 +6384,7 @@ ${peer.address}`
6254
6384
  return !!a && !!b && norm(a) === norm(b);
6255
6385
  }
6256
6386
  var DK_FALLBACK_ICE_SERVERS = [
6257
- { urls: "stun:stun.l.google.com:19302" },
6258
- { urls: "turn:tokyo.fi.chat:3478", username: "allcom", credential: "allcompass" },
6259
- { urls: "turn:tokyo.fi.chat:3478?transport=tcp", username: "allcom", credential: "allcompass" }
6387
+ { urls: "stun:stun.l.google.com:19302" }
6260
6388
  ];
6261
6389
  var DK_LIVE_ICE_SERVERS = [];
6262
6390
  var _dkIcePromise = null;
@@ -6324,13 +6452,27 @@ ${peer.address}`
6324
6452
  } catch (e) {
6325
6453
  console.warn("[rtc] call-ice-servers fetch failed", e);
6326
6454
  }
6327
- console.warn("[rtc] falling back to tokyo TURN \u2014 web\u2194Android online ICE may fail");
6455
+ console.warn("[rtc] call-ice-servers unavailable \u2014 STUN only until the host answers");
6328
6456
  DK_LIVE_ICE_SERVERS.splice(0, DK_LIVE_ICE_SERVERS.length, ...DK_FALLBACK_ICE_SERVERS.map((s) => ({ ...s })));
6329
6457
  await dkWarmCallIce(DK_LIVE_ICE_SERVERS);
6330
6458
  return DK_LIVE_ICE_SERVERS;
6331
6459
  })();
6332
6460
  return _dkIcePromise;
6333
6461
  }
6462
+ async function dkFreshIceServers() {
6463
+ try {
6464
+ const r = await fetch("/api/call-ice-servers", { headers: { "cache-control": "no-cache" } });
6465
+ const d = await r.json();
6466
+ if (d && d.ok && Array.isArray(d.iceServers) && d.iceServers.length) {
6467
+ DK_LIVE_ICE_SERVERS.splice(0, DK_LIVE_ICE_SERVERS.length, ...d.iceServers);
6468
+ return d.iceServers;
6469
+ }
6470
+ } catch (e) {
6471
+ }
6472
+ if (DK_LIVE_ICE_SERVERS.length)
6473
+ return DK_LIVE_ICE_SERVERS.slice();
6474
+ return dkLoadCallIceServers();
6475
+ }
6334
6476
  function dkAwaitCallIceServers(ms) {
6335
6477
  const budget = typeof ms === "number" ? ms : 1e4;
6336
6478
  return Promise.race([
@@ -6344,7 +6486,84 @@ ${peer.address}`
6344
6486
  }, budget))
6345
6487
  ]).then(() => DK_LIVE_ICE_SERVERS);
6346
6488
  }
6347
- dkLoadCallIceServers();
6489
+ var dkIsTurn = (u) => /^turns?:/i.test(String(u || ""));
6490
+ function dkTurnOnly(list) {
6491
+ const out = [];
6492
+ for (const e of list || []) {
6493
+ const urls = (Array.isArray(e.urls) ? e.urls : [e.urls]).filter(dkIsTurn);
6494
+ if (urls.length)
6495
+ out.push(Object.assign({}, e, { urls: Array.isArray(e.urls) ? urls : urls[0] }));
6496
+ }
6497
+ return out;
6498
+ }
6499
+ function dkStunOnly(list) {
6500
+ const out = [];
6501
+ for (const e of list || []) {
6502
+ const urls = (Array.isArray(e.urls) ? e.urls : [e.urls]).filter((u) => /^stuns?:/i.test(String(u || "")));
6503
+ if (urls.length)
6504
+ out.push({ urls: Array.isArray(e.urls) ? urls : urls[0] });
6505
+ }
6506
+ return out;
6507
+ }
6508
+ var DK_CALL_STUN_SERVERS = [{ urls: "stun:stun.l.google.com:19302" }];
6509
+ function dkRefreshCallStun() {
6510
+ const seen = new Set(DK_CALL_STUN_SERVERS.map((e) => JSON.stringify(e.urls)));
6511
+ for (const e of dkStunOnly(DK_LIVE_ICE_SERVERS)) {
6512
+ if (!seen.has(JSON.stringify(e.urls))) {
6513
+ DK_CALL_STUN_SERVERS.push(e);
6514
+ seen.add(JSON.stringify(e.urls));
6515
+ }
6516
+ }
6517
+ }
6518
+ function dkStaticCallTurn() {
6519
+ const live = dkTurnOnly(DK_LIVE_ICE_SERVERS);
6520
+ return live.length ? live : dkTurnOnly(DK_FALLBACK_ICE_SERVERS);
6521
+ }
6522
+ var dkCallTurnSource = /* @__PURE__ */ (() => {
6523
+ let current = [];
6524
+ let lastSource = "";
6525
+ return {
6526
+ async iceServers() {
6527
+ try {
6528
+ const r = await fetch("/api/call-turn-servers", { headers: { "cache-control": "no-cache" } });
6529
+ const d = await r.json();
6530
+ if (d && d.ok && Array.isArray(d.iceServers) && d.iceServers.length) {
6531
+ current = dkTurnOnly(d.iceServers);
6532
+ if (current.length) {
6533
+ if (d.source !== lastSource)
6534
+ console.log("[rtc] call TURN from " + d.source + ":", current.map((s) => s.urls));
6535
+ lastSource = d.source;
6536
+ return current.map((e) => Object.assign({}, e));
6537
+ }
6538
+ }
6539
+ } catch (e) {
6540
+ }
6541
+ await dkLoadCallIceServers().catch(() => {
6542
+ });
6543
+ current = dkStaticCallTurn();
6544
+ if (lastSource !== "static")
6545
+ console.log("[rtc] call TURN from today's entries:", current.map((s) => s.urls));
6546
+ lastSource = "static";
6547
+ return current.map((e) => Object.assign({}, e));
6548
+ },
6549
+ currentIceServers() {
6550
+ return (current.length ? current : dkStaticCallTurn()).map((e) => Object.assign({}, e));
6551
+ }
6552
+ };
6553
+ })();
6554
+ function dkCallRelayOnly() {
6555
+ try {
6556
+ if (/[?&]relay=1(&|$)/.test(location.search))
6557
+ return true;
6558
+ return localStorage.getItem("dk.callRelayOnly") === "1";
6559
+ } catch (e) {
6560
+ return false;
6561
+ }
6562
+ }
6563
+ dkLoadCallIceServers().then(dkRefreshCallStun, () => {
6564
+ });
6565
+ dkCallTurnSource.iceServers().catch(() => {
6566
+ });
6348
6567
  function dkRtcParseEnvelope(data) {
6349
6568
  const text = String(data || "").replace(/\0+$/u, "").trim();
6350
6569
  if (!text)
@@ -6652,10 +6871,12 @@ ${peer.address}`
6652
6871
  const engine = new CallEngine({
6653
6872
  selfId,
6654
6873
  signaling,
6655
- createPeerConnection: (c) => new RTCPeerConnection(c),
6874
+ // Debug only (dkCallRelayOnly): relay candidates only, to test TURN.
6875
+ createPeerConnection: (c) => new RTCPeerConnection(dkCallRelayOnly() ? Object.assign({}, c, { iceTransportPolicy: "relay" }) : c),
6656
6876
  getLocalMedia: (k) => navigator.mediaDevices.getUserMedia({ audio: k.audio, video: k.video }),
6657
6877
  getDisplayMedia: (c) => navigator.mediaDevices.getDisplayMedia(c || { video: true, audio: false }),
6658
- iceServers: DK_LIVE_ICE_SERVERS,
6878
+ iceServers: DK_CALL_STUN_SERVERS,
6879
+ turnServers: dkCallTurnSource,
6659
6880
  logger: (m) => console.log(m)
6660
6881
  });
6661
6882
  if (cancelled) {
@@ -6712,7 +6933,7 @@ ${peer.address}`
6712
6933
  setSharing(false);
6713
6934
  });
6714
6935
  engineRef.current = engine;
6715
- console.log("[call] CallEngine ready with ICE:", DK_LIVE_ICE_SERVERS.map((s) => s.urls));
6936
+ console.log("[call] CallEngine ready; STUN:", DK_CALL_STUN_SERVERS.map((s) => s.urls), "TURN: per call from the RSP node, else today's entries", dkCallRelayOnly() ? "(relay only \u2014 debug)" : "");
6716
6937
  })().catch((e) => console.warn("[call] engine init failed", e));
6717
6938
  return () => {
6718
6939
  cancelled = true;
@@ -6833,9 +7054,20 @@ ${peer.address}`
6833
7054
  const inc = incomingRef.current;
6834
7055
  if (inc && sameCall(inc.callId, env.callId))
6835
7056
  return;
6836
- setIncoming({ callId: env.callId, peerId: userid, video: !!env.video, audio: true, ringOnly: true, callName: env.callName || env.name });
7057
+ const via = env.via === "rsp-doorbell" || env.via === "rsp" ? env.via : "doorbell";
7058
+ setIncoming({
7059
+ callId: env.callId,
7060
+ peerId: userid,
7061
+ video: !!env.video,
7062
+ audio: true,
7063
+ ringOnly: true,
7064
+ via,
7065
+ callName: env.callName || env.name
7066
+ });
6837
7067
  if (onCallLogRef.current)
6838
7068
  onCallLogRef.current(userid, !!env.video, "incoming");
7069
+ if (via !== "doorbell")
7070
+ return;
6839
7071
  try {
6840
7072
  bus.send(userid, window.PeerWebRTC.encodeSignal({ type: "event", event: "ringing", callId: env.callId })).catch(() => {
6841
7073
  });
@@ -7052,7 +7284,7 @@ ${peer.address}`
7052
7284
  return null;
7053
7285
  const peer = (peers || []).find((p) => p.id === inc.peerId) || { id: inc.peerId };
7054
7286
  const name = verifiedLabel(inc.peerId, peer.alias) || peer.name || shortKey(inc.peerId, 10, 6);
7055
- return /* @__PURE__ */ React.createElement("div", { style: { position: "fixed", inset: 0, zIndex: 80, background: "color-mix(in oklab, var(--bg), transparent 15%)", display: "flex", alignItems: "center", justifyContent: "center" } }, /* @__PURE__ */ React.createElement("div", { style: { width: 320, padding: 26, borderRadius: 18, background: "var(--panel)", border: "1px solid var(--line)", textAlign: "center", boxShadow: "0 20px 60px rgba(0,0,0,0.4)" } }, /* @__PURE__ */ React.createElement("div", { style: { position: "relative", display: "inline-flex", alignItems: "center", justifyContent: "center", marginBottom: 14 } }, /* @__PURE__ */ React.createElement("span", { style: { position: "absolute", width: 96, height: 96, borderRadius: 999, border: "2px solid var(--accent)", animation: "dkpulse 2s ease-out infinite" } }), /* @__PURE__ */ React.createElement(DkIdenticon, { seed: inc.peerId, size: 72, radius: 18 })), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 17, fontWeight: 700, color: "var(--text)" } }, name), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 12.5, color: "var(--faint)", marginTop: 4, display: "flex", gap: 6, alignItems: "center", justifyContent: "center" } }, /* @__PURE__ */ React.createElement(Icon, { name: inc.video ? "video" : "phone", size: 14, stroke: 2 }), T && (inc.video ? T.incomingVideo : T.incomingAudio) || "Incoming " + (inc.video ? "video" : "audio") + " call"), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", gap: 14, justifyContent: "center", marginTop: 22 } }, /* @__PURE__ */ React.createElement(CallBtn, { icon: "phone", label: T && T.decline || "Decline", danger: true, onClick: ctl.reject }), /* @__PURE__ */ React.createElement(CallBtn, { icon: inc.video ? "video" : "phone", label: T && T.accept || "Accept", active: true, onClick: ctl.accept }))));
7287
+ return /* @__PURE__ */ React.createElement("div", { "data-testid": "incoming-call", style: { position: "fixed", inset: 0, zIndex: DK_Z_INCOMING_CALL, background: "color-mix(in oklab, var(--bg), transparent 15%)", display: "flex", alignItems: "center", justifyContent: "center" } }, /* @__PURE__ */ React.createElement("div", { style: { width: 320, padding: 26, borderRadius: 18, background: "var(--panel)", border: "1px solid var(--line)", textAlign: "center", boxShadow: "0 20px 60px rgba(0,0,0,0.4)" } }, /* @__PURE__ */ React.createElement("div", { style: { position: "relative", display: "inline-flex", alignItems: "center", justifyContent: "center", marginBottom: 14 } }, /* @__PURE__ */ React.createElement("span", { style: { position: "absolute", width: 96, height: 96, borderRadius: 999, border: "2px solid var(--accent)", animation: "dkpulse 2s ease-out infinite" } }), /* @__PURE__ */ React.createElement(DkIdenticon, { seed: inc.peerId, size: 72, radius: 18 })), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 17, fontWeight: 700, color: "var(--text)" } }, name), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 12.5, color: "var(--faint)", marginTop: 4, display: "flex", gap: 6, alignItems: "center", justifyContent: "center" } }, /* @__PURE__ */ React.createElement(Icon, { name: inc.video ? "video" : "phone", size: 14, stroke: 2 }), T && (inc.video ? T.incomingVideo : T.incomingAudio) || "Incoming " + (inc.video ? "video" : "audio") + " call"), (inc.via === "rsp" || inc.via === "rsp-doorbell") && /* @__PURE__ */ React.createElement("div", { style: { color: "var(--faint)", fontSize: 12, marginTop: 6 } }, inc.via === "rsp-doorbell" ? "RSP \xB7 Doorbell" : "RSP"), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", gap: 14, justifyContent: "center", marginTop: 22 } }, /* @__PURE__ */ React.createElement(CallBtn, { icon: "phone", label: T && T.decline || "Decline", danger: true, onClick: ctl.reject }), /* @__PURE__ */ React.createElement(CallBtn, { icon: inc.video ? "video" : "phone", label: T && T.accept || "Accept", active: true, onClick: ctl.accept }))));
7056
7288
  }
7057
7289
  function CallBtn({ icon, label, onClick, active, danger, wide }) {
7058
7290
  const bg = danger ? "var(--danger)" : active ? "var(--accent)" : "var(--chip)";
@@ -7105,7 +7337,7 @@ ${peer.address}`
7105
7337
  };
7106
7338
  const canShare = connected && typeof navigator !== "undefined" && navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia;
7107
7339
  const controls = /* @__PURE__ */ React.createElement("div", { style: { display: "flex", gap: 18, alignItems: "flex-start" } }, /* @__PURE__ */ React.createElement(CallBtn, { icon: muted ? "micFill" : "mic", label: muted ? T && T.unmute || "unmute" : T && T.mute || "mute", active: muted, onClick: toggleMute }), canShare && /* @__PURE__ */ React.createElement(CallBtn, { icon: "monitor", label: ctl.sharing ? T && T.stopShare || "stop share" : T && T.share || "share", active: ctl.sharing, onClick: ctl.toggleShare }), /* @__PURE__ */ React.createElement(CallBtn, { icon: "phone", label: T && T.endCall || "end", danger: true, wide: true, onClick: ctl.hangup }));
7108
- return /* @__PURE__ */ React.createElement("div", { style: { position: "fixed", inset: 0, zIndex: 70, background: "var(--bg)", display: "flex", flexDirection: "column" } }, ctl.remoteStream && /* @__PURE__ */ React.createElement(AudioSink, { stream: ctl.remoteStream }), /* @__PURE__ */ React.createElement("div", { style: { height: 52, flexShrink: 0, display: "flex", alignItems: "center", gap: 10, padding: "0 18px", borderBottom: "1px solid var(--line)" } }, /* @__PURE__ */ React.createElement(Icon, { name: video ? "video" : "phone", size: 16, color: "var(--accent)", stroke: 2 }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 13, fontWeight: 700, color: "var(--text)" } }, name), /* @__PURE__ */ React.createElement(Tag, { tone: callStateTone(call.ended ? call.state : connected ? "connected" : call.state) }, stateLabel), noticeText && /* @__PURE__ */ React.createElement(Tag, { tone: "danger" }, noticeText), /* @__PURE__ */ React.createElement("div", { style: { flex: 1 } }), connected && /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 14, fontWeight: 700, color: "var(--text)", letterSpacing: 1 } }, mm, ":", ss)), video ? (() => {
7340
+ return /* @__PURE__ */ React.createElement("div", { "data-testid": "call-overlay", style: { position: "fixed", inset: 0, zIndex: DK_Z_CALL_OVERLAY, background: "var(--bg)", display: "flex", flexDirection: "column" } }, ctl.remoteStream && /* @__PURE__ */ React.createElement(AudioSink, { stream: ctl.remoteStream }), /* @__PURE__ */ React.createElement("div", { style: { height: 52, flexShrink: 0, display: "flex", alignItems: "center", gap: 10, padding: "0 18px", borderBottom: "1px solid var(--line)" } }, /* @__PURE__ */ React.createElement(Icon, { name: video ? "video" : "phone", size: 16, color: "var(--accent)", stroke: 2 }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 13, fontWeight: 700, color: "var(--text)" } }, name), /* @__PURE__ */ React.createElement(Tag, { tone: callStateTone(call.ended ? call.state : connected ? "connected" : call.state) }, stateLabel), noticeText && /* @__PURE__ */ React.createElement(Tag, { tone: "danger" }, noticeText), /* @__PURE__ */ React.createElement("div", { style: { flex: 1 } }), connected && /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 14, fontWeight: 700, color: "var(--text)", letterSpacing: 1 } }, mm, ":", ss)), video ? (() => {
7109
7341
  const tiles = [
7110
7342
  { key: "remote", stream: ctl.remoteStream, label: name, mirror: false },
7111
7343
  { key: "local", stream: ctl.localStream, label: ctl.sharing ? T && T.yourScreen || "Your screen" : T && T.you || "You", mirror: !ctl.sharing }
@@ -7308,274 +7540,312 @@ ${peer.address}`
7308
7540
  }
7309
7541
  ));
7310
7542
  }
7311
- var DK_FILE_RTC_KIND = "file";
7312
- var DK_FILE_RTC_CHUNK = 16 * 1024;
7313
- var DK_FILE_RTC_OPEN_TIMEOUT_MS = 2e4;
7314
- var DK_FILE_RTC_SIGNAL_TTL_MS = 10 * 60 * 1e3;
7315
- var _dkFileIcePromise = null;
7316
- function dkFileIceServers() {
7317
- if (!_dkFileIcePromise)
7318
- _dkFileIcePromise = dkLoadCallIceServers();
7319
- return _dkFileIcePromise;
7320
- }
7321
- function dkFileRtcId() {
7322
- if (window.crypto && window.crypto.randomUUID)
7323
- return window.crypto.randomUUID();
7324
- return "frtc-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2);
7325
- }
7326
- function dkFileRtcEnvelope(fileId, type, extra) {
7327
- return Object.assign({ dkRtc: 1, kind: DK_FILE_RTC_KIND, fileId, type, ts: Date.now() }, extra || {});
7328
- }
7329
- function dkRtcState(pc) {
7543
+ var FILE_RTC_KIND = "file";
7544
+ var FILE_RTC_CHUNK = 16 * 1024;
7545
+ var FILE_RTC_SIGNAL_TTL_MS = 10 * 60 * 1e3;
7546
+ var DEFAULTS = {
7547
+ openTimeoutMs: 2e4,
7548
+ // DataChannel open
7549
+ offerResendMs: 3e3,
7550
+ // sender: repeat the offer until answered
7551
+ highWater: 4 * 1024 * 1024,
7552
+ // in-flight bytes before the send loop waits
7553
+ bufferWaitMs: 3e4,
7554
+ // per wait below highWater
7555
+ drainIdleMs: 3e4,
7556
+ // drain to 0: give up after this long with no progress
7557
+ ackTimeoutMs: 2e4,
7558
+ // "got" after the drain
7559
+ byeGraceMs: 3e4,
7560
+ // receiver: bye before done
7561
+ ackLingerMs: 5e3,
7562
+ // receiver: close after "got" if the sender has not
7563
+ closeDelayMs: 1500
7564
+ // sender: close after its own bye
7565
+ };
7566
+ function rtcState(pc) {
7330
7567
  if (!pc)
7331
7568
  return "";
7332
7569
  return "ice=" + pc.iceConnectionState + " conn=" + pc.connectionState + " gather=" + pc.iceGatheringState;
7333
7570
  }
7334
- function dkWaitForOpen(dc, timeoutMs, describeState) {
7571
+ function waitForOpen(dc, timeoutMs, describe) {
7335
7572
  if (dc.readyState === "open")
7336
7573
  return Promise.resolve();
7337
7574
  return new Promise((resolve, reject) => {
7338
- const timer = setTimeout(() => {
7575
+ const fail = (what) => () => {
7339
7576
  cleanup();
7340
- const s = describeState ? describeState() : "";
7341
- reject(new Error("WebRTC data channel open timed out" + (s ? " (" + s + ")" : "")));
7342
- }, timeoutMs);
7343
- const cleanup = () => {
7344
- clearTimeout(timer);
7345
- dc.removeEventListener("open", onOpen);
7346
- dc.removeEventListener("error", onError);
7347
- dc.removeEventListener("close", onClose);
7577
+ const s = describe();
7578
+ reject(new Error("WebRTC data channel " + what + (s ? " (" + s + ")" : "")));
7348
7579
  };
7349
7580
  const onOpen = () => {
7350
7581
  cleanup();
7351
7582
  resolve();
7352
7583
  };
7353
- const onError = () => {
7354
- cleanup();
7355
- const s = describeState ? describeState() : "";
7356
- reject(new Error("WebRTC data channel failed" + (s ? " (" + s + ")" : "")));
7357
- };
7358
- const onClose = () => {
7359
- cleanup();
7360
- const s = describeState ? describeState() : "";
7361
- reject(new Error("WebRTC data channel closed before open" + (s ? " (" + s + ")" : "")));
7362
- };
7584
+ const onError = fail("failed");
7585
+ const onClose = fail("closed before open");
7586
+ const timer = setTimeout(fail("open timed out"), timeoutMs);
7587
+ function cleanup() {
7588
+ clearTimeout(timer);
7589
+ dc.removeEventListener("open", onOpen);
7590
+ dc.removeEventListener("error", onError);
7591
+ dc.removeEventListener("close", onClose);
7592
+ }
7363
7593
  dc.addEventListener("open", onOpen);
7364
7594
  dc.addEventListener("error", onError);
7365
7595
  dc.addEventListener("close", onClose);
7366
7596
  });
7367
7597
  }
7368
- function dkWaitBufferedLow(dc, highWater) {
7369
- if (dc.bufferedAmount < highWater)
7598
+ function waitBuffered(dc, limit, idleMs) {
7599
+ if (dc.bufferedAmount < limit)
7370
7600
  return Promise.resolve();
7371
7601
  return new Promise((resolve, reject) => {
7372
7602
  const prev = dc.bufferedAmountLowThreshold;
7373
- dc.bufferedAmountLowThreshold = Math.floor(highWater / 2);
7374
- let poll = null;
7375
- let timer = null;
7376
- const done = () => {
7377
- cleanup();
7378
- resolve();
7379
- };
7380
- const cleanup = () => {
7381
- if (poll)
7382
- clearInterval(poll);
7383
- if (timer)
7384
- clearTimeout(timer);
7385
- dc.removeEventListener("bufferedamountlow", done);
7386
- dc.removeEventListener("close", onClose);
7387
- dc.removeEventListener("error", onError);
7388
- dc.bufferedAmountLowThreshold = prev;
7389
- };
7603
+ dc.bufferedAmountLowThreshold = Math.max(0, Math.floor((limit - 1) / 2));
7604
+ let last = dc.bufferedAmount;
7605
+ let lastMoved = Date.now();
7390
7606
  const check = () => {
7391
7607
  if (dc.readyState !== "open")
7392
- return onClose();
7393
- if (dc.bufferedAmount < highWater)
7394
- done();
7395
- };
7396
- const onClose = () => {
7397
- cleanup();
7398
- reject(new Error("WebRTC data channel closed while draining"));
7399
- };
7400
- const onError = () => {
7401
- cleanup();
7402
- reject(new Error("WebRTC data channel failed while draining"));
7608
+ return finish(new Error("WebRTC data channel closed while draining"));
7609
+ if (dc.bufferedAmount < limit)
7610
+ return finish(null);
7611
+ if (dc.bufferedAmount < last) {
7612
+ last = dc.bufferedAmount;
7613
+ lastMoved = Date.now();
7614
+ } else if (Date.now() - lastMoved > idleMs)
7615
+ finish(new Error("WebRTC data channel drain stalled buffered=" + dc.bufferedAmount));
7403
7616
  };
7404
- dc.addEventListener("bufferedamountlow", done);
7405
- dc.addEventListener("close", onClose);
7406
- dc.addEventListener("error", onError);
7407
- poll = setInterval(check, 250);
7408
- timer = setTimeout(() => {
7409
- cleanup();
7410
- reject(new Error("WebRTC data channel drain timed out buffered=" + dc.bufferedAmount));
7411
- }, 3e4);
7617
+ const onErr = () => finish(new Error("WebRTC data channel failed while draining"));
7618
+ const poll = setInterval(check, 100);
7619
+ function finish(err) {
7620
+ clearInterval(poll);
7621
+ dc.removeEventListener("bufferedamountlow", check);
7622
+ dc.removeEventListener("close", check);
7623
+ dc.removeEventListener("error", onErr);
7624
+ dc.bufferedAmountLowThreshold = prev;
7625
+ if (err)
7626
+ reject(err);
7627
+ else
7628
+ resolve();
7629
+ }
7630
+ dc.addEventListener("bufferedamountlow", check);
7631
+ dc.addEventListener("close", check);
7632
+ dc.addEventListener("error", onErr);
7412
7633
  });
7413
7634
  }
7414
- function dkFileDownload(blob, name) {
7415
- const url = URL.createObjectURL(blob);
7416
- const a = document.createElement("a");
7417
- a.href = url;
7418
- a.download = name || "agentnet-file";
7419
- a.textContent = name || "agentnet-file";
7420
- return { url, name: a.download };
7421
- }
7422
- function dkRememberRtcFile(peerId, fileId, name, size, url) {
7423
- if (!window.__dkRtcFiles)
7424
- window.__dkRtcFiles = /* @__PURE__ */ new Map();
7425
- const item = { id: fileId, peerId, name, size, url, media: dkFileMediaKind(name) };
7426
- window.__dkRtcFiles.set(peerId + "|" + name + "|" + size, item);
7427
- return item;
7428
- }
7429
- function useRtcFileController(selfId, onReceivedFile) {
7430
- const [incoming, setIncoming] = React.useState([]);
7431
- const peersRef = React.useRef(/* @__PURE__ */ new Map());
7432
- const onReceivedFileRef = React.useRef(onReceivedFile);
7433
- React.useEffect(() => {
7434
- onReceivedFileRef.current = onReceivedFile;
7435
- }, [onReceivedFile]);
7436
- React.useEffect(() => {
7437
- if (!selfId || !window.RTCPeerConnection || !window.dkRtcSignalBus)
7635
+ function createFileRtcEngine(o) {
7636
+ const opt = Object.assign({}, DEFAULTS, o.options || {});
7637
+ const log = o.log || (() => {
7638
+ });
7639
+ const newId = o.newId || (() => globalThis.crypto && globalThis.crypto.randomUUID ? globalThis.crypto.randomUUID() : "frtc-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2));
7640
+ const PC = o.RTCPeerConnection;
7641
+ const sessions = /* @__PURE__ */ new Map();
7642
+ const finished = /* @__PURE__ */ new Map();
7643
+ const ended = /* @__PURE__ */ new Map();
7644
+ const envelope = (fileId, type, extra) => Object.assign({ dkRtc: 1, kind: FILE_RTC_KIND, fileId, type, ts: Date.now() }, extra || {});
7645
+ const signal = (peerId, fileId, type, extra) => o.bus.send(peerId, envelope(fileId, type, extra));
7646
+ let off = null;
7647
+ const pruneFinished = () => {
7648
+ const cut = Date.now() - FILE_RTC_SIGNAL_TTL_MS;
7649
+ for (const [id, at] of finished)
7650
+ if (at < cut)
7651
+ finished.delete(id);
7652
+ for (const [id, at] of ended)
7653
+ if (at < cut)
7654
+ ended.delete(id);
7655
+ };
7656
+ const closeRecv = (fileId) => {
7657
+ const s = sessions.get(fileId);
7658
+ if (!s)
7438
7659
  return;
7439
- const bus = dkRtcSignalBus();
7440
- const cleanup = (fileId) => {
7441
- const sess = peersRef.current.get(fileId);
7442
- if (!sess)
7660
+ if (s.graceTimer)
7661
+ clearTimeout(s.graceTimer);
7662
+ if (s.lingerTimer)
7663
+ clearTimeout(s.lingerTimer);
7664
+ try {
7665
+ s.dc && s.dc.close();
7666
+ } catch (e) {
7667
+ }
7668
+ try {
7669
+ s.pc && s.pc.close();
7670
+ } catch (e) {
7671
+ }
7672
+ sessions.delete(fileId);
7673
+ ended.set(fileId, Date.now());
7674
+ };
7675
+ const attachChannel = (peerId, fileId, s, dc) => {
7676
+ dc.binaryType = "arraybuffer";
7677
+ s.dc = dc;
7678
+ dc.onmessage = (ev) => {
7679
+ if (typeof ev.data === "string") {
7680
+ let msg = null;
7681
+ try {
7682
+ msg = JSON.parse(ev.data);
7683
+ } catch (e) {
7684
+ }
7685
+ if (!msg)
7686
+ return;
7687
+ if (msg.type === "meta") {
7688
+ s.meta = msg;
7689
+ s.chunks = [];
7690
+ s.received = 0;
7691
+ } else if (msg.type === "done") {
7692
+ if (s.completed)
7693
+ return;
7694
+ s.completed = true;
7695
+ finished.set(fileId, Date.now());
7696
+ if (s.graceTimer) {
7697
+ clearTimeout(s.graceTimer);
7698
+ s.graceTimer = null;
7699
+ }
7700
+ const meta = s.meta || {};
7701
+ const blob = new Blob(s.chunks, { type: meta.mime || "application/octet-stream" });
7702
+ try {
7703
+ if (o.onReceived)
7704
+ o.onReceived({ peerId, fileId, name: meta.name || "agentnet-file", mime: meta.mime, size: blob.size, blob });
7705
+ } catch (e) {
7706
+ log("[file-rtc] onReceived failed: " + (e && e.message || e));
7707
+ }
7708
+ try {
7709
+ dc.send(JSON.stringify({ type: "got", bytes: s.received }));
7710
+ } catch (e) {
7711
+ }
7712
+ s.lingerTimer = setTimeout(() => closeRecv(fileId), opt.ackLingerMs);
7713
+ } else if (msg.type === "cancel") {
7714
+ closeRecv(fileId);
7715
+ }
7443
7716
  return;
7444
- try {
7445
- sess.dc && sess.dc.close();
7446
- } catch (e) {
7447
- }
7448
- try {
7449
- sess.pc && sess.pc.close();
7450
- } catch (e) {
7451
7717
  }
7452
- peersRef.current.delete(fileId);
7718
+ s.chunks.push(ev.data);
7719
+ s.received += ev.data.byteLength || ev.data.size || 0;
7453
7720
  };
7454
- const sendSignal = (peerId, fileId, type, extra) => bus.send(peerId, dkFileRtcEnvelope(fileId, type, extra));
7455
- const handleDataChannel = (peerId, fileId, pc, dc, initialMeta) => {
7456
- dc.binaryType = "arraybuffer";
7457
- const prev = peersRef.current.get(fileId);
7458
- const sess = Object.assign(prev || {}, { pc, dc, peerId, meta: initialMeta || null, chunks: [], received: 0 });
7459
- peersRef.current.set(fileId, sess);
7460
- dc.onmessage = (ev) => {
7461
- if (typeof ev.data === "string") {
7462
- let msg = null;
7721
+ dc.onclose = () => setTimeout(() => closeRecv(fileId), 1e3);
7722
+ dc.onerror = () => closeRecv(fileId);
7723
+ };
7724
+ const onSignal = async (peerId, env) => {
7725
+ if (!env || !env.fileId || !env.type)
7726
+ return;
7727
+ if (Date.now() - (env.ts || Date.now()) > FILE_RTC_SIGNAL_TTL_MS)
7728
+ return;
7729
+ const fileId = env.fileId;
7730
+ const s = sessions.get(fileId);
7731
+ try {
7732
+ if (env.type === "offer") {
7733
+ pruneFinished();
7734
+ if (finished.has(fileId) || ended.has(fileId)) {
7735
+ log("[file-rtc] offer for a finished transfer ignored " + fileId);
7736
+ return;
7737
+ }
7738
+ if (s) {
7739
+ if (s.answerSdp && s.peerId === peerId)
7740
+ signal(peerId, fileId, "answer", { sdp: s.answerSdp }).catch(() => {
7741
+ });
7742
+ return;
7743
+ }
7744
+ const sess = { peerId, pc: null, dc: null, meta: env.meta || null, chunks: [], received: 0, pendingCandidates: [], completed: false, answerSdp: null };
7745
+ sessions.set(fileId, sess);
7746
+ const pc = new PC({ iceServers: await o.iceServers() });
7747
+ sess.pc = pc;
7748
+ pc.oniceconnectionstatechange = () => log("[file-rtc] receiver ice=" + pc.iceConnectionState + " conn=" + pc.connectionState);
7749
+ pc.onconnectionstatechange = () => log("[file-rtc] receiver conn=" + pc.connectionState + " ice=" + pc.iceConnectionState);
7750
+ pc.onicecandidate = (ev) => {
7751
+ if (ev.candidate)
7752
+ signal(peerId, fileId, "candidate", { candidate: ev.candidate.toJSON ? ev.candidate.toJSON() : ev.candidate }).catch(() => {
7753
+ });
7754
+ };
7755
+ pc.ondatachannel = (ev) => attachChannel(peerId, fileId, sess, ev.channel);
7756
+ await pc.setRemoteDescription({ type: "offer", sdp: env.sdp });
7757
+ for (const c of sess.pendingCandidates.splice(0)) {
7463
7758
  try {
7464
- msg = JSON.parse(ev.data);
7759
+ await pc.addIceCandidate(c);
7465
7760
  } catch (e) {
7466
7761
  }
7467
- if (!msg)
7468
- return;
7469
- if (msg.type === "meta") {
7470
- sess.meta = msg;
7471
- sess.chunks = [];
7472
- sess.received = 0;
7473
- } else if (msg.type === "done") {
7474
- const meta = sess.meta || {};
7475
- const blob = new Blob(sess.chunks, { type: meta.mime || "application/octet-stream" });
7476
- const dl = dkFileDownload(blob, meta.name || "agentnet-file");
7477
- dkRememberRtcFile(peerId, fileId, dl.name, blob.size, dl.url);
7478
- setIncoming((arr) => [{ id: fileId, peerId, name: dl.name, size: blob.size, url: dl.url }].concat(arr).slice(0, 8));
7479
- if (onReceivedFileRef.current)
7480
- onReceivedFileRef.current(peerId, dl.name, blob);
7481
- cleanup(fileId);
7482
- } else if (msg.type === "cancel") {
7483
- cleanup(fileId);
7484
- }
7485
- return;
7486
7762
  }
7487
- sess.chunks.push(ev.data);
7488
- sess.received += ev.data.byteLength || ev.data.size || 0;
7489
- };
7490
- dc.onclose = () => setTimeout(() => cleanup(fileId), 1e3);
7491
- dc.onerror = () => cleanup(fileId);
7492
- };
7493
- const off = bus.on(DK_FILE_RTC_KIND, async (peerId, env) => {
7494
- if (!env || !env.fileId || !env.type)
7763
+ const answer = await pc.createAnswer();
7764
+ await pc.setLocalDescription(answer);
7765
+ sess.answerSdp = answer.sdp;
7766
+ await signal(peerId, fileId, "answer", { sdp: answer.sdp });
7767
+ } else if (env.type === "candidate" && s && env.candidate) {
7768
+ if (s.pc && s.pc.remoteDescription) {
7769
+ try {
7770
+ await s.pc.addIceCandidate(env.candidate);
7771
+ } catch (e) {
7772
+ }
7773
+ } else
7774
+ (s.pendingCandidates = s.pendingCandidates || []).push(env.candidate);
7775
+ } else if (env.type === "bye" && s) {
7776
+ if (s.completed || env.reason === "fallback")
7777
+ closeRecv(fileId);
7778
+ else if (!s.graceTimer)
7779
+ s.graceTimer = setTimeout(() => {
7780
+ log("[file-rtc] no data after bye, closing " + fileId);
7781
+ closeRecv(fileId);
7782
+ }, opt.byeGraceMs);
7783
+ } else if (env.type === "answer" || env.type === "candidate") {
7784
+ await onSenderSignal(peerId, env);
7785
+ }
7786
+ } catch (e) {
7787
+ log("[file-rtc] signal failed " + (e && e.message || e));
7788
+ closeRecv(fileId);
7789
+ }
7790
+ };
7791
+ const senders = /* @__PURE__ */ new Map();
7792
+ const onSenderSignal = async (peerId, env) => {
7793
+ const s = senders.get(env.fileId);
7794
+ if (!s || s.peerId !== peerId)
7795
+ return;
7796
+ if (env.type === "answer") {
7797
+ if (s.pc.signalingState !== "have-local-offer") {
7798
+ log("[file-rtc] stale answer ignored for " + env.fileId + " state=" + s.pc.signalingState);
7495
7799
  return;
7496
- if (Date.now() - (env.ts || Date.now()) > DK_FILE_RTC_SIGNAL_TTL_MS)
7800
+ }
7801
+ if (s.stopResend)
7802
+ s.stopResend();
7803
+ await s.pc.setRemoteDescription({ type: "answer", sdp: env.sdp });
7804
+ for (const c of s.pendingCandidates.splice(0)) {
7805
+ try {
7806
+ await s.pc.addIceCandidate(c);
7807
+ } catch (e) {
7808
+ }
7809
+ }
7810
+ } else if (env.type === "candidate" && env.candidate) {
7811
+ if (s.pc.remoteDescription) {
7812
+ try {
7813
+ await s.pc.addIceCandidate(env.candidate);
7814
+ } catch (e) {
7815
+ }
7816
+ } else
7817
+ s.pendingCandidates.push(env.candidate);
7818
+ }
7819
+ };
7820
+ async function sendFile(peerId, file, onProgress) {
7821
+ const fileId = newId();
7822
+ const pc = new PC({ iceServers: await o.iceServers() });
7823
+ const dc = pc.createDataChannel("agentnet-file", { ordered: true });
7824
+ const s = { peerId, pc, dc, pendingCandidates: [], stopResend: null };
7825
+ senders.set(fileId, s);
7826
+ let acked = null;
7827
+ const ack = new Promise((resolve) => {
7828
+ acked = resolve;
7829
+ });
7830
+ dc.addEventListener("message", (ev) => {
7831
+ if (typeof ev.data !== "string")
7497
7832
  return;
7498
- const fileId = env.fileId;
7499
- let sess = peersRef.current.get(fileId);
7500
7833
  try {
7501
- if (env.type === "offer") {
7502
- if (sess && sess.pc && sess.pc.signalingState !== "closed") {
7503
- console.warn("[file-rtc] duplicate offer ignored for " + fileId);
7504
- return;
7505
- }
7506
- const pc = new RTCPeerConnection({ iceServers: await dkFileIceServers() });
7507
- pc.oniceconnectionstatechange = () => console.warn("[file-rtc] receiver ice=" + pc.iceConnectionState + " conn=" + pc.connectionState);
7508
- pc.onconnectionstatechange = () => console.warn("[file-rtc] receiver conn=" + pc.connectionState + " ice=" + pc.iceConnectionState);
7509
- pc.onicecandidate = (ev) => {
7510
- if (ev.candidate)
7511
- sendSignal(peerId, fileId, "candidate", { candidate: ev.candidate.toJSON() }).catch(() => {
7512
- });
7513
- };
7514
- pc.ondatachannel = (ev) => handleDataChannel(peerId, fileId, pc, ev.channel, env.meta || null);
7515
- peersRef.current.set(fileId, { pc, dc: null, peerId, chunks: [], meta: env.meta || null, pendingCandidates: [] });
7516
- await pc.setRemoteDescription({ type: "offer", sdp: env.sdp });
7517
- sess = peersRef.current.get(fileId);
7518
- if (sess && sess.pendingCandidates) {
7519
- for (const c of sess.pendingCandidates.splice(0)) {
7520
- try {
7521
- await pc.addIceCandidate(c);
7522
- } catch (e) {
7523
- }
7524
- }
7525
- }
7526
- const answer = await pc.createAnswer();
7527
- await pc.setLocalDescription(answer);
7528
- await sendSignal(peerId, fileId, "answer", { sdp: answer.sdp });
7529
- } else if (env.type === "answer" && sess) {
7530
- if (sess.pc.signalingState !== "have-local-offer") {
7531
- console.warn("[file-rtc] stale answer ignored for " + fileId + " state=" + sess.pc.signalingState);
7532
- return;
7533
- }
7534
- await sess.pc.setRemoteDescription({ type: "answer", sdp: env.sdp });
7535
- if (sess.pendingCandidates) {
7536
- for (const c of sess.pendingCandidates.splice(0)) {
7537
- try {
7538
- await sess.pc.addIceCandidate(c);
7539
- } catch (e) {
7540
- }
7541
- }
7542
- }
7543
- } else if (env.type === "candidate" && sess && env.candidate) {
7544
- if (sess.pc.remoteDescription) {
7545
- try {
7546
- await sess.pc.addIceCandidate(env.candidate);
7547
- } catch (e) {
7548
- }
7549
- } else {
7550
- if (!sess.pendingCandidates)
7551
- sess.pendingCandidates = [];
7552
- sess.pendingCandidates.push(env.candidate);
7553
- }
7554
- } else if (env.type === "bye") {
7555
- cleanup(fileId);
7556
- }
7834
+ const m = JSON.parse(ev.data);
7835
+ if (m && m.type === "got")
7836
+ acked(m);
7557
7837
  } catch (e) {
7558
- console.warn("[file-rtc] signal failed", e);
7559
- cleanup(fileId);
7560
7838
  }
7561
7839
  });
7562
- return () => {
7563
- off();
7564
- for (const id of Array.from(peersRef.current.keys()))
7565
- cleanup(id);
7840
+ let resendTimer = null;
7841
+ s.stopResend = () => {
7842
+ if (resendTimer) {
7843
+ clearInterval(resendTimer);
7844
+ resendTimer = null;
7845
+ }
7566
7846
  };
7567
- }, [selfId]);
7568
- const sendFile = React.useCallback(async (peerId, file, onProgress) => {
7569
- if (!peerId || !file || !window.RTCPeerConnection || !window.dkRtcSignalBus) {
7570
- return { ok: false, fallback: true, error: "WebRTC unavailable" };
7571
- }
7572
- const bus = dkRtcSignalBus();
7573
- const fileId = dkFileRtcId();
7574
- const pc = new RTCPeerConnection({ iceServers: await dkFileIceServers() });
7575
- const dc = pc.createDataChannel("agentnet-file", { ordered: true });
7576
- const sess = { pc, dc, peerId, chunks: [], meta: null, pendingCandidates: [] };
7577
- peersRef.current.set(fileId, sess);
7578
7847
  const cleanup = () => {
7848
+ s.stopResend();
7579
7849
  try {
7580
7850
  dc.close();
7581
7851
  } catch (e) {
@@ -7584,70 +7854,180 @@ ${peer.address}`
7584
7854
  pc.close();
7585
7855
  } catch (e) {
7586
7856
  }
7587
- peersRef.current.delete(fileId);
7857
+ senders.delete(fileId);
7588
7858
  };
7589
- const sendSignal = (type, extra) => bus.send(peerId, dkFileRtcEnvelope(fileId, type, extra));
7590
7859
  try {
7591
- pc.oniceconnectionstatechange = () => console.warn("[file-rtc] sender ice=" + pc.iceConnectionState + " conn=" + pc.connectionState);
7592
- pc.onconnectionstatechange = () => console.warn("[file-rtc] sender conn=" + pc.connectionState + " ice=" + pc.iceConnectionState);
7860
+ pc.oniceconnectionstatechange = () => log("[file-rtc] sender ice=" + pc.iceConnectionState + " conn=" + pc.connectionState);
7861
+ pc.onconnectionstatechange = () => log("[file-rtc] sender conn=" + pc.connectionState + " ice=" + pc.iceConnectionState);
7593
7862
  pc.onicecandidate = (ev) => {
7594
7863
  if (ev.candidate)
7595
- sendSignal("candidate", { candidate: ev.candidate.toJSON() }).catch(() => {
7864
+ signal(peerId, fileId, "candidate", { candidate: ev.candidate.toJSON ? ev.candidate.toJSON() : ev.candidate }).catch(() => {
7596
7865
  });
7597
7866
  };
7598
7867
  const offer = await pc.createOffer();
7599
7868
  await pc.setLocalDescription(offer);
7600
- await sendSignal("offer", {
7601
- sdp: offer.sdp,
7602
- meta: { name: file.name, size: file.size, mime: file.type || "application/octet-stream" }
7603
- });
7604
- await dkWaitForOpen(dc, DK_FILE_RTC_OPEN_TIMEOUT_MS, () => dkRtcState(pc));
7605
- dc.send(JSON.stringify({ type: "meta", name: file.name, size: file.size, mime: file.type || "application/octet-stream" }));
7869
+ const mime = file.type || "application/octet-stream";
7870
+ const meta = { name: file.name, size: file.size, mime };
7871
+ await signal(peerId, fileId, "offer", { sdp: offer.sdp, meta });
7872
+ let resends = 0;
7873
+ resendTimer = setInterval(() => {
7874
+ if (pc.signalingState !== "have-local-offer" || dc.readyState !== "connecting") {
7875
+ s.stopResend();
7876
+ return;
7877
+ }
7878
+ resends++;
7879
+ log("[file-rtc] no answer yet, offer resent (" + resends + ") " + fileId);
7880
+ const sdp = pc.localDescription && pc.localDescription.sdp || offer.sdp;
7881
+ signal(peerId, fileId, "offer", { sdp, meta }).catch(() => {
7882
+ });
7883
+ }, opt.offerResendMs);
7884
+ try {
7885
+ await waitForOpen(dc, opt.openTimeoutMs, () => rtcState(pc));
7886
+ } finally {
7887
+ s.stopResend();
7888
+ }
7889
+ dc.send(JSON.stringify({ type: "meta", name: file.name, size: file.size, mime }));
7606
7890
  let sent = 0;
7607
7891
  const startedAt = Date.now();
7608
7892
  let lastProgressAt = 0;
7609
- const highWater = 4 * 1024 * 1024;
7610
- const reportProgress = (force) => {
7893
+ const report = (force) => {
7611
7894
  if (!onProgress)
7612
7895
  return;
7613
- const now = Date.now();
7614
- if (!force && now - lastProgressAt < 250 && sent < file.size)
7896
+ const t = Date.now();
7897
+ if (!force && t - lastProgressAt < 250 && sent < file.size)
7615
7898
  return;
7616
- lastProgressAt = now;
7617
- const elapsedMs = Math.max(1, now - startedAt);
7618
- const kbps = sent / 1024 / (elapsedMs / 1e3);
7619
- onProgress({
7620
- sent,
7621
- size: file.size,
7622
- pct: file.size ? sent / file.size * 100 : 100,
7623
- kbps,
7624
- elapsedMs,
7625
- via: "webrtc"
7626
- });
7899
+ lastProgressAt = t;
7900
+ const elapsedMs = Math.max(1, t - startedAt);
7901
+ onProgress({ sent, size: file.size, pct: file.size ? sent / file.size * 100 : 100, kbps: sent / 1024 / (elapsedMs / 1e3), elapsedMs, via: "webrtc" });
7627
7902
  };
7628
- reportProgress(true);
7903
+ report(true);
7629
7904
  while (sent < file.size) {
7630
7905
  if (dc.readyState !== "open")
7631
7906
  throw new Error("WebRTC data channel closed");
7632
- const end = Math.min(file.size, sent + DK_FILE_RTC_CHUNK);
7633
- const buf = await file.slice(sent, end).arrayBuffer();
7634
- dc.send(buf);
7907
+ const end = Math.min(file.size, sent + FILE_RTC_CHUNK);
7908
+ dc.send(await file.slice(sent, end).arrayBuffer());
7635
7909
  sent = end;
7636
- reportProgress(false);
7637
- await dkWaitBufferedLow(dc, highWater);
7910
+ report(false);
7911
+ await waitBuffered(dc, opt.highWater, opt.bufferWaitMs);
7638
7912
  }
7639
- reportProgress(true);
7640
7913
  dc.send(JSON.stringify({ type: "done" }));
7641
- await sendSignal("bye", { reason: "done" }).catch(() => {
7914
+ await waitBuffered(dc, 1, opt.drainIdleMs);
7915
+ const got = await Promise.race([
7916
+ ack,
7917
+ new Promise((_, rej) => {
7918
+ if (dc.readyState !== "open") {
7919
+ rej(new Error("receiver closed without acknowledging"));
7920
+ return;
7921
+ }
7922
+ const t = setTimeout(() => rej(new Error("no acknowledgement from the receiver")), opt.ackTimeoutMs);
7923
+ dc.addEventListener("close", () => {
7924
+ clearTimeout(t);
7925
+ rej(new Error("receiver closed without acknowledging"));
7926
+ });
7927
+ })
7928
+ ]);
7929
+ if (got.bytes != null && got.bytes !== file.size)
7930
+ throw new Error("receiver got " + got.bytes + " of " + file.size + " bytes");
7931
+ report(true);
7932
+ await signal(peerId, fileId, "bye", { reason: "done" }).catch(() => {
7642
7933
  });
7643
- setTimeout(cleanup, 1500);
7934
+ setTimeout(cleanup, opt.closeDelayMs);
7644
7935
  return { ok: true, via: "webrtc", fileId };
7645
7936
  } catch (e) {
7646
- await sendSignal("bye", { reason: "fallback" }).catch(() => {
7937
+ await signal(peerId, fileId, "bye", { reason: "fallback" }).catch(() => {
7647
7938
  });
7648
7939
  cleanup();
7649
7940
  return { ok: false, fallback: true, error: e && e.message || String(e) };
7650
7941
  }
7942
+ }
7943
+ return {
7944
+ start() {
7945
+ if (!off)
7946
+ off = o.bus.on(FILE_RTC_KIND, (peerId, env) => onSignal(peerId, env));
7947
+ },
7948
+ stop() {
7949
+ if (off) {
7950
+ off();
7951
+ off = null;
7952
+ }
7953
+ for (const id of Array.from(sessions.keys()))
7954
+ closeRecv(id);
7955
+ for (const s of senders.values()) {
7956
+ try {
7957
+ s.dc.close();
7958
+ } catch (e) {
7959
+ }
7960
+ try {
7961
+ s.pc.close();
7962
+ } catch (e) {
7963
+ }
7964
+ }
7965
+ senders.clear();
7966
+ },
7967
+ sendFile,
7968
+ // for tests
7969
+ _sessions: sessions,
7970
+ _finished: finished,
7971
+ _ended: ended
7972
+ };
7973
+ }
7974
+ function dkFileIceServers() {
7975
+ return dkFreshIceServers();
7976
+ }
7977
+ function dkFileDownload(blob, name) {
7978
+ const url = URL.createObjectURL(blob);
7979
+ const a = document.createElement("a");
7980
+ a.href = url;
7981
+ a.download = name || "agentnet-file";
7982
+ a.textContent = name || "agentnet-file";
7983
+ return { url, name: a.download };
7984
+ }
7985
+ function dkRememberRtcFile(peerId, fileId, name, size, url) {
7986
+ if (!window.__dkRtcFiles)
7987
+ window.__dkRtcFiles = /* @__PURE__ */ new Map();
7988
+ const item = { id: fileId, peerId, name, size, url, media: dkFileMediaKind(name) };
7989
+ window.__dkRtcFiles.set(peerId + "|" + name + "|" + size, item);
7990
+ return item;
7991
+ }
7992
+ function useRtcFileController(selfId, onReceivedFile) {
7993
+ const [incoming, setIncoming] = React.useState([]);
7994
+ const onReceivedFileRef = React.useRef(onReceivedFile);
7995
+ React.useEffect(() => {
7996
+ onReceivedFileRef.current = onReceivedFile;
7997
+ }, [onReceivedFile]);
7998
+ const engineRef = React.useRef(null);
7999
+ const engine = () => {
8000
+ if (!engineRef.current && window.RTCPeerConnection && window.dkRtcSignalBus) {
8001
+ engineRef.current = createFileRtcEngine({
8002
+ bus: dkRtcSignalBus(),
8003
+ RTCPeerConnection: window.RTCPeerConnection,
8004
+ iceServers: dkFileIceServers,
8005
+ log: (m) => console.warn(m),
8006
+ onReceived: ({ peerId, fileId, name, size, blob }) => {
8007
+ const dl = dkFileDownload(blob, name);
8008
+ dkRememberRtcFile(peerId, fileId, dl.name, size, dl.url);
8009
+ setIncoming((arr) => [{ id: fileId, peerId, name: dl.name, size, url: dl.url }].concat(arr).slice(0, 8));
8010
+ if (onReceivedFileRef.current)
8011
+ onReceivedFileRef.current(peerId, dl.name, blob);
8012
+ }
8013
+ });
8014
+ }
8015
+ return engineRef.current;
8016
+ };
8017
+ React.useEffect(() => {
8018
+ if (!selfId)
8019
+ return void 0;
8020
+ const e = engine();
8021
+ if (!e)
8022
+ return void 0;
8023
+ e.start();
8024
+ return () => e.stop();
8025
+ }, [selfId]);
8026
+ const sendFile = React.useCallback(async (peerId, file, onProgress) => {
8027
+ const e = engine();
8028
+ if (!peerId || !file || !e)
8029
+ return { ok: false, fallback: true, error: "WebRTC unavailable" };
8030
+ return e.sendFile(peerId, file, onProgress);
7651
8031
  }, []);
7652
8032
  const dismissIncoming = React.useCallback((id) => {
7653
8033
  setIncoming((arr) => {
@@ -8148,6 +8528,15 @@ ${peer.address}`
8148
8528
  updLanNoRestart: "Installed, but the daemon did not come back within a minute \u2014 the new version applies on its next start.",
8149
8529
  pubOpen: "View public profile",
8150
8530
  pubNone: "No public profile \u2014 this user has not registered a beagles.eth name.",
8531
+ friendPlatform: "Platform",
8532
+ friendOsVersion: "OS version",
8533
+ friendAppVersion: "App version",
8534
+ friendRspNotAdvertised: "Not advertised",
8535
+ status: "Status",
8536
+ statusOnline: "Online",
8537
+ statusOffline: "Offline",
8538
+ lastSeen: "last seen",
8539
+ website: "website",
8151
8540
  ensNoEthWallet: "no Ethereum wallet extension found (MetaMask\u2026)",
8152
8541
  ensNoSolWallet: "no Solana wallet extension found (Phantom\u2026)",
8153
8542
  ensWalletOwned: "registered via your mobile wallet as",
@@ -8385,6 +8774,15 @@ ${peer.address}`
8385
8774
  updLanNoRestart: "\u5DF2\u5B89\u88C5,\u4F46 daemon \u4E00\u5206\u949F\u5185\u6CA1\u6709\u91CD\u65B0\u8D77\u6765\u2014\u2014\u4E0B\u6B21\u542F\u52A8\u65F6\u751F\u6548\u3002",
8386
8775
  pubOpen: "\u67E5\u770B\u516C\u5F00\u8D44\u6599",
8387
8776
  pubNone: "\u6682\u65E0\u516C\u5F00\u8D44\u6599\u2014\u2014\u5BF9\u65B9\u8FD8\u6CA1\u6709\u6CE8\u518C beagles.eth \u540D\u5B57\u3002",
8777
+ friendPlatform: "\u5E73\u53F0",
8778
+ friendOsVersion: "\u7CFB\u7EDF\u7248\u672C",
8779
+ friendAppVersion: "\u5E94\u7528\u7248\u672C",
8780
+ friendRspNotAdvertised: "\u672A\u58F0\u660E\u652F\u6301",
8781
+ status: "\u72B6\u6001",
8782
+ statusOnline: "\u5728\u7EBF",
8783
+ statusOffline: "\u79BB\u7EBF",
8784
+ lastSeen: "\u6700\u540E\u5728\u7EBF",
8785
+ website: "\u7F51\u7AD9",
8388
8786
  ensNoEthWallet: "\u672A\u68C0\u6D4B\u5230\u4EE5\u592A\u574A\u94B1\u5305\u63D2\u4EF6(MetaMask \u7B49)",
8389
8787
  ensNoSolWallet: "\u672A\u68C0\u6D4B\u5230 Solana \u94B1\u5305\u63D2\u4EF6(Phantom \u7B49)",
8390
8788
  ensWalletOwned: "\u5DF2\u901A\u8FC7\u624B\u673A\u94B1\u5305\u6CE8\u518C\u4E3A",
@@ -8956,19 +9354,20 @@ ${peer.address}`
8956
9354
  });
8957
9355
  if (!peerTakesRtcFile(peerId))
8958
9356
  return toxcore();
9357
+ const viaCarrier = (rtcError) => toxcore().then((rr) => Object.assign({}, rr, { rtcFailed: true, rtcError: rtcError || "WebRTC file send failed" }));
8959
9358
  return rtcFileCtl.sendFile(peerId, file, onProgress).then((r) => {
8960
9359
  if (r && r.ok && r.via === "webrtc") {
8961
9360
  return fetch(
8962
9361
  "/api/webrtc-file-save?dir=out&userid=" + encodeURIComponent(peerId) + "&name=" + encodeURIComponent(file.name),
8963
9362
  { method: "POST", body: file }
8964
- ).then(() => {
9363
+ ).catch(() => null).then(() => {
8965
9364
  data.loadThread(peerId);
8966
9365
  data.refresh();
8967
9366
  return { ok: true, via: "webrtc" };
8968
9367
  });
8969
9368
  }
8970
- return toxcore();
8971
- }).catch(() => toxcore());
9369
+ return viaCarrier(r && r.error);
9370
+ }, (e) => viaCarrier(e && e.message || String(e)));
8972
9371
  };
8973
9372
  const onSendRtcFile = (file, onProgress) => {
8974
9373
  if (!activeId || !file)