@decentnetwork/peer 0.1.39 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/peer.js CHANGED
@@ -592,8 +592,8 @@ export class Peer {
592
592
  }
593
593
  this.#debugLog(`friend-request: announce stored on ${this.#lastSelfAnnounceStoredCount} node(s) before send`);
594
594
  const appPayload = encodeFriendRequestPacket({
595
- name: PEER_NICKNAME,
596
- descr: PEER_STATUS_MESSAGE || "decent peer",
595
+ name: this.#opts.nickname ?? PEER_NICKNAME,
596
+ descr: (this.#opts.statusMessage ?? PEER_STATUS_MESSAGE) || "decent peer",
597
597
  hello: hello ?? ""
598
598
  });
599
599
  const friendReqPayload = concatBytes([
@@ -2812,9 +2812,11 @@ export class Peer {
2812
2812
  // callback. Most Carrier UIs read the displayed name from the
2813
2813
  // userinfo flatbuffers payload below, but this keeps both paths
2814
2814
  // consistent.
2815
- const nameBytes = new TextEncoder().encode(PEER_NICKNAME);
2815
+ const nick = this.#opts.nickname ?? PEER_NICKNAME;
2816
+ const descr = this.#opts.statusMessage ?? PEER_STATUS_MESSAGE;
2817
+ const nameBytes = new TextEncoder().encode(nick);
2816
2818
  await this.#sendMessengerPacket(friendId, PACKET_ID_NICKNAME, nameBytes);
2817
- this.#debugLog(`nickname "${PEER_NICKNAME}" sent to ${friendId}`);
2819
+ this.#debugLog(`nickname "${nick}" sent to ${friendId}`);
2818
2820
  // Carrier C SDK transports its full user-profile (name, descr,
2819
2821
  // gender, phone, email, region, has_avatar) as a FlatBuffers
2820
2822
  // PACKET_TYPE_USERINFO (3) payload sent via toxcore's
@@ -2826,11 +2828,11 @@ export class Peer {
2826
2828
  // __flatbuffers_soffset_read_from_pe (observed in Beagle 1.8.6).
2827
2829
  await sleep(250);
2828
2830
  const userInfo = encodeUserInfoPacket({
2829
- name: PEER_NICKNAME,
2830
- descr: PEER_STATUS_MESSAGE
2831
+ name: nick,
2832
+ descr
2831
2833
  });
2832
2834
  await this.#sendMessengerPacket(friendId, PACKET_ID_STATUSMESSAGE, userInfo);
2833
- this.#debugLog(`userinfo sent to ${friendId} (name="${PEER_NICKNAME}", descr="${PEER_STATUS_MESSAGE}")`);
2835
+ this.#debugLog(`userinfo sent to ${friendId} (name="${nick}", descr="${descr}")`);
2834
2836
  }
2835
2837
  catch (error) {
2836
2838
  this.#debugLog(`send profile failed for ${friendId}: ${error.message}`);
@@ -40,6 +40,16 @@ export type PeerOptions = {
40
40
  * optimisation only applies to packet 64 and custom-id data is duplicated.
41
41
  */
42
42
  bulkDataPacketId?: number;
43
+ /**
44
+ * Display name this peer advertises to friends (Carrier nickname, packet 48 +
45
+ * the userinfo profile). Without it every node reports the build default
46
+ * "@decentnetwork/peer" and friend lists can't tell anyone apart. decentlan
47
+ * passes its node name (e.g. "mac-dev", "cn", "tokyo"). Falls back to
48
+ * DECENT_PEER_NAME / the build default when unset.
49
+ */
50
+ nickname?: string;
51
+ /** Status/description line shown alongside the nickname. */
52
+ statusMessage?: string;
43
53
  compatibilityMode?: CompatibilityMode;
44
54
  debugLabel?: string;
45
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Pure TypeScript port of Elastos Carrier (toxcore-derived) P2P messaging. DHT, onion routing, TCP relay, FlatBuffers app payloads, Express offline relay. Wire-compatible with iOS Beagle and the Carrier C SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",