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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@6thquake/inohupwebsocket

v0.1.1

Published

nohup websocket client with karn, ping pong, sub, friendly api and so on.

Downloads

17

Readme

iNohupWebSocket

Websocket工具类,除支持原生Websocket方法外,还支持自动重连、Ping Pong、Notification的操作,接收服务端消息后的api封装处理,消息订阅等。

Requirements

q >= 1.5.1

install

  • using npm
$ npm install @6thquake/inohupwebsocket
  • using yarn
$ yarn add @6thquake/inohupwebsocket

build

  • gulp
$ npm install gulp
  • dependencies
$ npm install
  • build
$ gulp

Usage

  1. 在html里引入q、iNohupWebSocket

    <script type="text/javascript" src="http://apps.bdimg.com/libs/q.js/2.0.1/q.js"></script>
    <script type="text/javascript" src="https://github.com/6thquake/iNohupWebSocket/tree/master/dist/NohupWebSocket.js"></script>
  2. 初始化

    var ws = NohupWebSocket.getInstance('ws://xxx', protocol, options);
    // 参数和原生websocket的参数保持一致,options多了两个可选属性 maxReconnectWaitTime reconnectBaseTime
    // maxReconnectWaitTime:重连最大等待时间,默认30s
    // reconnectBaseTime:重连采用指数退避算法,reconnectBaseTime为底数,默认2
  3. 基本功能

    1. 设置事件处理函数(onopen、onclose、onconnecting、onmessage、onerror)

      ws.onopen = function(event){};
      ws.onconnecting = function(event){};
      ws.onmessage = function(event){};
      ws.onerror = function(event){};
      ws.onclose = function(event){};
    2. 发送消息(send)

      ws.send({
        url: 'tsbot/cases/437'
      }).then(function (data) {
        console.log("success");
      }, function (err) {
        console.log("error");
      }, function (n) {
        console.log("fially");
      });
    3. 消息订阅(sub、psub、unsub、unpsub)

      /**
       * 1. 客户端send数据:此接口模拟http协议,提供url来确定频道,可以使用restful接口来定义和后端服务的映射关系,
       * 参数可以放在链接上也可以通过?来分隔链接和参数,e.g.
       *    1. { url: 'users/1', method:'GET' }
       *    2. { url: 'users/1?name=xxx' }
       *
       * 2. 服务端响应:对应服务端需要将请求的数据返回回来,e.g.
       *    {
       *      request: {
       *         url: 'users/1'
       *      },
       *      data: {}, //数据
       *      type: 'NOTIFICATION' // 可选 NOTIFICATION(自动调用浏览器的Notification api)
       *    }
       *
       * 3. 对应的客户端处理数据:
       *  ws.sub({
       *     url: 'users/1'
       *  }).then(success, error, finally);
       *
       *  ws.psub({
       *     url: 'users/*'
       *  }).progress(function(data){});
       *  
       *  ws.notification().progress(function(data){}); // 处理服务端返回的type为NOTIFICATION的所有消息
       */
      
      // 按频道订阅 
      ws.sub({
        url: "tsbot/cases/437"
      }).then(function (data) {
        console.log("success");
      }, function (err) {
        console.log("error");
      }, function (n) {
        console.log("fially");
      });
            
      // 支持按正则表达式订阅
      ws.psub({
        url: "tsbot/cases/*"
      }).progress(function (data) {
        console.log("success");
      };
      
      // 按频道解除订阅
      ws.unsub({
        url: "tsbot/cases/437"
      })
      
      // 按正则解除订阅
      ws.unpsub({
        url: "tsbot/cases/*"
      })
    4. close 、refresh

      
      ws.refresh();
      
      ws.close();
      
需要引入Q,支持AMD、CMD