npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

p2p-im-cli

v3.0.2

Published

P2P CLI instant messenger — text chat, file transfer, group rooms, watchdog, store-and-forward

Readme

p2p-im-cli (WebRTC Edition)

P2P 即时通讯 CLI 程序,基于 TypeScript / Node.js / WebRTC DataChannel。

核心目标:在不同 WiFi、不同 NAT 网络下尽可能直连通信。

  • 同网段:优先本地候选地址直连
  • 跨公网:自动通过 STUN 尝试打洞
  • 打洞失败:可配置 TURN 中继兜底
  • 仅握手阶段依赖信令服务器(交换 SDP/ICE)

功能特性

| 功能 | 说明 | |------|------| | 文字聊天 | 直接输入文字即可向对端发送消息 | | 文件传输 | /send 分块传输任意文件,带进度显示 | | 群聊房间 | 一方创建房间,其他人通过 房主昵称+房间ID 申请加入 | | 连接审批 | A 连接 B 或申请加入 B 的房间时,需 B 手动审批 | | Watchdog 心跳 | 定期 PING/PONG,断线自动检测 | | 存储转发 | 对方不在线时消息存入磁盘,上线后自动投递 | | 自动重连 | 断线后指数退避自动重连(最多5次),已审批对象自动放行 |

安装

npm install -g p2p-im-cli

或本地开发:

git clone <repo>
cd p2p-im-cli
npm install
npm link

快速开始

1) 启动信令服务器(任一公网可访问节点)

im-signal 8787

或本地开发:

npm run signal

默认监听:ws://0.0.0.0:8787

2) 启动客户端

im

输入:

  • 昵称
  • 信令地址(例如 ws://你的公网IP:8787

3) 按昵称连接

/connect Bob

4) 对端审批

/approve Alice
# 或
/deny Alice

命令参考

基本操作

/connect <昵称>
/disconnect [昵称]
/peers
/switch <昵称>
/status

审批

/pending
/approve <昵称>
/deny <昵称>

文件传输

/send <文件路径>
/accept <transferId>
/reject <transferId>

文件默认保存到 ~/Downloads/p2p-im/

群聊

/room create 我的房间
/room join <房主昵称> <房间ID>
/room leave
/room list
/rooms

NAT 穿透与 TURN 配置

STUN(默认已启用)

默认使用:stun:stun.l.google.com:19302

可通过环境变量覆盖:

IM_STUN_URL=stun:stun.example.com:3478

TURN(打洞失败时兜底)

配置以下环境变量即可启用:

IM_TURN_URL=turn:turn.example.com:3478
IM_TURN_USERNAME=your-user
IM_TURN_CREDENTIAL=your-password

协议

DataChannel 上传输 UTF-8 JSON 帧,结构如下:

{
  "id": "hex-id",
  "type": "CHAT",
  "from": "Alice",
  "ts": 1710000000000,
  "payload": { "text": "hello" }
}

消息类型沿用原版本(HELLO / CONN_PENDING / CONN_ACK / ROOM_* / FILE_* / PING / PONG)。

目录结构

bin/
  im.ts
  signal.ts                # 信令服务入口
src/
  app.ts                   # 主应用(审批、房间、消息路由)
  rtc.ts                   # WebRTC 会话管理(ICE/STUN/TURN)
  signaling-client.ts      # 客户端信令
  signaling-server.ts      # 最小信令服务
  peer.ts                  # DataChannel 封装
  file-transfer.ts
  room-manager.ts
  message-store.ts
  watchdog.ts
  protocol.ts
  types.ts
  ui.ts

注意事项

  • 本项目是端到端 P2P 架构,信令服务器不转发聊天内容,仅负责会话建立。
  • 若双方网络策略过于严格,必须配置可用 TURN 服务器才能保证连通。
  • 旧版基于 IP+端口 的 /connect/room join 参数已变更为基于昵称。

License

MIT