@decentnetwork/lan 0.1.224 → 0.1.225

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.
@@ -41,6 +41,9 @@ export interface IpcHandlers {
41
41
  friendsReject: (userid: string) => Promise<void>;
42
42
  /** Send a chat message (Carrier text, packet 64) to a friend and log it. */
43
43
  chatSend: (userid: string, text: string) => Promise<void>;
44
+ /** Append a local-only chat history entry. Used for browser-local events such
45
+ * as WebRTC file receive; does not transmit anything to the peer. */
46
+ chatLogLocal: (userid: string, dir: "in" | "out", text: string) => Promise<void>;
44
47
  /** Return persisted chat history. With `peer`, returns just that thread and
45
48
  * honours `before`/`limit` pagination; without, every thread (legacy shape). */
46
49
  chatHistory: (peer?: string, before?: number, limit?: number) => Promise<Record<string, unknown>>;
@@ -115,11 +118,12 @@ export interface IpcHandlers {
115
118
  selfRestart: () => Promise<Record<string, unknown>>;
116
119
  }
117
120
  export interface IpcRequest {
118
- op: "friend-request" | "ping" | "diag" | "friends-pending" | "friends-accept" | "friends-reject" | "chat-send" | "chat-history" | "friends-list" | "friend-remove" | "friend-set-alias" | "friends-autoaccept" | "set-profile" | "file-send" | "file-delete" | "file-cancel" | "file-retry" | "chat-mark-read" | "subscribe" | "sign" | "call-signal" | "call-poll" | "proxy-reload" | "proxy-access" | "self-restart";
121
+ op: "friend-request" | "ping" | "diag" | "friends-pending" | "friends-accept" | "friends-reject" | "chat-send" | "chat-log-local" | "chat-history" | "friends-list" | "friend-remove" | "friend-set-alias" | "friends-autoaccept" | "set-profile" | "file-send" | "file-delete" | "file-cancel" | "file-retry" | "chat-mark-read" | "subscribe" | "sign" | "call-signal" | "call-poll" | "proxy-reload" | "proxy-access" | "self-restart";
119
122
  address?: string;
120
123
  hello?: string;
121
124
  userid?: string;
122
125
  text?: string;
126
+ dir?: "in" | "out";
123
127
  alias?: string;
124
128
  name?: string;
125
129
  description?: string;
@@ -196,6 +196,12 @@ export class IpcServer {
196
196
  await this.handlers.chatSend(req.userid, req.text ?? "");
197
197
  return;
198
198
  }
199
+ case "chat-log-local": {
200
+ if (!req.userid)
201
+ throw new Error("userid is required");
202
+ await this.handlers.chatLogLocal(req.userid, req.dir === "out" ? "out" : "in", req.text ?? "");
203
+ return;
204
+ }
199
205
  case "chat-history":
200
206
  return await this.handlers.chatHistory(req.userid, req.before, req.limit);
201
207
  case "friends-list":
@@ -381,6 +381,11 @@ export class DaemonServer {
381
381
  this.ipcEvents.emit("event", { type: "chat", userid, dir: "out" });
382
382
  this.logger.info(`Queued text for offline ${userid.slice(0, 8)} (delivers on reconnect)`);
383
383
  },
384
+ chatLogLocal: async (userid, dir, text) => {
385
+ if (!text)
386
+ return;
387
+ this.logChat(userid, dir, text);
388
+ },
384
389
  chatHistory: async (peer, before, limit) => {
385
390
  return { chats: this.messageStore?.history(peer, { before, limit }) ?? {} };
386
391
  },
@@ -220,6 +220,7 @@ function dkCopyLegacy(s) {
220
220
  }
221
221
  const dkApi = {
222
222
  send: (userid, text) => dkPost("/api/chat-send", { userid, text }),
223
+ logLocal: (userid, dir, text) => dkPost("/api/chat-log-local", { userid, dir, text }),
223
224
  add: (address) => dkPost("/api/add", { address }),
224
225
  accept: (userid) => dkPost("/api/accept", { userid }),
225
226
  reject: (userid) => dkPost("/api/reject", { userid }),
@@ -2683,7 +2684,12 @@ function DkApp() {
2683
2684
  const rowPad = t.density === "comfortable" ? "11px 12px" : "7px 10px";
2684
2685
  const callCtl = useCallController(me.userId);
2685
2686
  const onCall = (peerId, video) => callCtl.start(peerId, !!video);
2686
- const rtcFileCtl = useRtcFileController(me.userId);
2687
+ const rtcFileCtl = useRtcFileController(me.userId, (peerId, text) => {
2688
+ dkApi.logLocal(peerId, "in", text).then(() => {
2689
+ data.loadThread(peerId);
2690
+ data.refresh();
2691
+ });
2692
+ });
2687
2693
  React.useEffect(() => {
2688
2694
  if (!activeId && peers.length) setActiveId(peers[0].id);
2689
2695
  }, [peers, activeId]);
package/dist/ui/server.js CHANGED
@@ -650,6 +650,12 @@ export function startFriendUi(opts) {
650
650
  sendJson(res, r.ok ? 200 : 400, r);
651
651
  return;
652
652
  }
653
+ if (req.method === "POST" && url === "/api/chat-log-local") {
654
+ const { userid, dir, text } = await readBody(req);
655
+ const r = await opts.call({ op: "chat-log-local", userid, dir: dir === "out" ? "out" : "in", text });
656
+ sendJson(res, r.ok ? 200 : 400, r);
657
+ return;
658
+ }
653
659
  if (req.method === "POST" && url === "/api/chat-mark-read") {
654
660
  const { userid } = await readBody(req);
655
661
  const r = await opts.call({ op: "chat-mark-read", userid });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/lan",
3
- "version": "0.1.224",
3
+ "version": "0.1.225",
4
4
  "description": "Private virtual LAN for self-hosted services and AI agents, built on Elastos Carrier. NAT-traversal, name service, ACL, all over a peer-to-peer mesh — no public IP required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",