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

@vshen/v-socket-js-sdk

v1.0.5

Published

这是一个用于前端实现长连接的SDK,需要搭配 [v-socket](https://github.com/vaas1993/v-socket) 使用。

Readme

说明

这是一个用于前端实现长连接的SDK,需要搭配 v-socket 使用。

安装

npm install v-socket-js-sdk --save

使用

let instance = new VSocket()

// 登录,三个参数从后端返回,具体见 v-socket 文档
insatnce.login(server, appid, password)

// 接收消息事件
instance.onReceive(message => {
    // WebSocket消息只支持字符串,若需要其它格式需要序列化返回,然后前端在这里反序列化后使用
    console.log(message)
})

方法

  • close()

关闭连接,关闭成功时会触发连接关闭事件

  • heartbeat()

心跳,执行该方法后会定时发送心跳包保持连接活跃,默认不执行

  • setHeartbeatInterval(millisecond)

设置心跳间隔,默认 10000 毫秒

  • getHeartbeatInterval()

获取当前心跳间隔

  • login(server, appid, password)

登录连接消息,三个参数需要建议从后端返回,具体见 v-socket 文档

  • setReconnectCount(number)

设置断线重试次数,默认为 3 次,设置为 0 表示不自动重试

  • getReconnectCount()

获取断线重试次数

  • onLoginSuccess(callback)

监听登录成功事件

  • offLoginSuccess(callback)

取消监听登录成功事件

  • onReceive(callback)

监听接收消息事件

  • offReceive(callback)

取消监听接收消息事件

  • onDisconnect(callback)

监听断开连接事件(手动调用 close 方法并且断开成功后,也会触发该事件)

  • offDisconnect(callback)

取消监听断开连接事件

  • onConnectFail(callback)

监听连接失败事件,调用 login 方法后如果连接失败则触发该事件,触发后不会自动重试

  • offConnectFail(callback)

取消监听连接失败事件

关于断线重连

适用版本:v1.0.5

用于连接的密码是一串包含时间戳的密文,v-socket 服务收到登录请求后会校验时间戳是否超过有效期, 所以断线重连时不能使用原来的密码来登录。

若需要断线重连,除了设置一个合适的重连次数外,还需要额外赋值一个获取连接配置方法 getConnectConfig

let instance = new VSocket()
// 给这个属性赋一个函数值
instance.getConnectConfig = async function() {
    return {
        server: String,
        appid: String,
        password: String
    }
}
// 直接调用登录方法,不需要再传参数
insatnce.login()