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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@findsoft/ws-heartbeat-ts

v0.8.3

Published

简单封装WebSocket的心跳检测和自动连接

Downloads

16

Readme

ws-heartbeat-ts

根据 websocket-heartbeat-js 编写的ts版本

How to use

  1. 使用 getInstance 获得ws实例, 而不是 new 关键字.
  2. 因为这可以确保对于相同的URL地址,当它不是初始调用时,它将获取现有实例,而不是创建相同URL的WS连接。
/** ts */
import WsHeartBeat from '@findsoft/ws-heartbeat-ts';
// your interface
interface IObj extends FWsData {
  id: string,
  typess: string
}
const wsInstance: WsHeartBeat = WsHeartBeat.getInstance(opt);
const myData = {id: 1, data: 2};
// 发送-json格式——自动 JSON.stringify
wsInstance.sendData( myData );
// 发送-普通格式
wsInstance.send( JSON.stringify(myData) );
// 接收-json格式(如果 JSON.parse 抛错,则会返回ws原始数据)
wsInstance.onmessage = (data: IObj, wsEvent: MessageEvent) => {
 console.log(data, 'data\nwsEvent', wsEvent);
};

Option

| 参数 | 是否必填 | 类型 | 默认 | 说明 | | ------ | ------ | ------ | ------ | ------ | | url | true | string | | ws地址 | | pingTimeout | false | number | 5000 | 心跳包发送频率 | | pongTimeout | false | number | 10000 | 超时时间,超过判定为断开 | | reconnectTimeout | false | number | 2000 | 重连延时,每time毫秒尝试重连 | | pingMsg | false | string | "{}" | 心跳包内容 | | repeatLimit | false | number | 5 | 尝试重连的次数 | | dataType | false | json/byte | 'json' | ws-message返回的数据格式 | | byteFormat | false| utf-8 | 'utf-8'| 如果为byte类型,编码方式为utf-8 |

约定

  1. 需要和后端讨论 收发消息 的数据格式

为什么用ts

  • ts可以使用singleton单例模式开发,在ts项目中,可以保证同一个ws地址,只会有一个连接( version >= 0.5.x)
  • ts可以自动生成 .d.ts 的声明文件 -->

备注

其他文档可以参见 websocket-heartbeat-js