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

event-server_js

v0.2.2

Published

Event server js api

Readme

Event Server

简介

一个简单的事件触发与监听服务器实现。

  • Publisher: Publisher 负责发布事件
  • Subscriber: Subscriber 负责监听并处理事件。使用一个 UserId 标识自己.
  • Target: 自定义目标。Subscriber 可以订阅 Target 的事件,Publisher 可以发布 Target 的事件。

事件分为两类:

  • Subscriber 事件: 此类事件仅与 Subscriber 用户本身相关.
  • Target 事件: 所有监听此 Target 的 Subscriber 都会收到此类事件.

特性:

  • Publisher 支持自动重连. 丢失链接状态下发布的事件会丢失。
  • Subscriber 支持自动重连. 重连后所有的监听事件状态会自动恢复,不需要重新设置事件监听.丢失链接状态下的事件会丢失.

安装

DevContainer

使用 vscode devcontainer 中打开项目根目录

安装依赖 packages

mix deps.get
npm install

服务器启动

mix phx.server

运行测试

node test.js

Docker

image: yuanlin2008/event_server:0.2

env

  • SECRET_KEY_BASE 密钥
  • PORT 监听端口
  • PUB_SECRET Publisher 登录密码

npm

EventServer 的 js API 可以从 npm 安装

npm install event-server_js

使用

注意: Publisher 和 Subscriber 在不使用后需要调用 stop()停止.

Publisher

import { Publisher } from "event-server_js"

const publisher = new Publisher(
  "ws://localhost:4000", // Pub地址
  "12345", // 登录密码
  10000, // 心跳间隔(10s)
  1000 //重连间隔(1s)
)

publisher.start()

// 触发用户事件
publisher.event(
  123, // user id
  "test_event", // event name
  { a: 10, b: 2 } // event payload
)

// 触发Target事件
publisher.targetEvent(
  "guild:1234", // Target
  "test_event", // event name
  { a: 10, b: 2 } // event payload
)

Subscriber

import { Subscriber } from "event-server_js"

const subscriber = new Subscriber(
  "ws://localhost:5000", // Sub地址
  123, // user id.
  10000, // 心跳间隔(10s)
  1000 //重连间隔(1s)
)

subscriber.start()

// 订阅用户事件.
subscriber.subscribe("test_event", (payload) => {
  console.log(payload)
})

// 订阅Target事件.
subscriber.subscribeTarget("guild:1234", "test_event", (payload) => {
  console.log(payload)
})