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

@kookapp/im-socket

v0.0.2

Published

IM WebSocket connection handling library

Readme

@kookapp/im-socket

KOOK IM 传输内核 — 平台无关的 WebSocket 连接管理。

是什么

@kookapp/im-socket 是 KOOK IM 三层架构的第一层(传输内核),负责:

  • WebSocket 连接与 Gateway 获取
  • 状态机、心跳保活、断线重连
  • 帧协议编解码、SN 重排、Resume 续传

本包不直接面向业务,由上层适配器(如 WebIMLibAdapter)封装后使用。详细架构与状态机见 architecture.md

快速使用

浏览器环境

import { IMSocket } from '@kookapp/im-socket'

const transport = new IMSocket({
  token: 'Bearer xxx',
  gatewayURL: 'https://api.kookapp.cn',
  compress: 1,
})

transport.on('message', (frame) => { /* 业务消息 */ })
transport.on('statechange', ({ from, to }) => { /* 状态变更 */ })

transport.start()

Node.js 环境

通过 createSocket 注入 ws 包,无需污染全局 WebSocket

import WebSocket from 'ws'
import { IMSocket } from '@kookapp/im-socket'

const transport = new IMSocket({
  token: 'Bot xxx',
  gatewayURL: 'https://www.kookapp.cn',
  compress: 0,
  createSocket: (url) => new WebSocket(url),
  gatewayProvider: async () => {
    const res = await fetch('https://www.kookapp.cn/api/v3/gateway/index?compress=0', {
      headers: { Authorization: 'Bot xxx' },
    })
    const data = await res.json()
    return { url: data.data.url }
  },
})

transport.on('message', (frame) => { /* 业务消息 */ })
transport.start()

更多 API、扩展点与常量见 architecture.md

依赖

  • eventemitter3
  • pako

零平台依赖,默认使用全局 WebSocket。Node.js 环境可通过 createSocket 注入 ws 等第三方实现。