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

@dabing_bigpawn/socket-util

v0.0.2

Published

[![NPM version](https://img.shields.io/npm/v/@dabing_bigpawn/socket-util.svg?style=flat)](https://npmjs.org/package/@dabing_bigpawn/socket-util) [![NPM downloads](http://img.shields.io/npm/dm/@dabing_bigpawn/socket-util.svg?style=flat)](https://npmjs.org/

Downloads

2

Readme

webSocketUtil

NPM version NPM downloads

Install

$ pnpm install
$ npm run dev
$ npm run build

Options

url:要连接的 WebSocket URL; protocols:一个协议字符串或者一个包含协议字符串的数组; query:可以通过 URL 传递给后端的查询参数; greet:心跳检测的打招呼信息; customBase:自定义的 baseURL。

onopen:触发 dep 内 open 对应的回调函数并且打开心跳检测; onclose:触发 dep 内 close 对应的回调函数并且对关闭的 code 码进行判断,如果是非正常关闭连接,将会进行重连,如果重连次数达到阈值,则通知给用户; onerror:触发 dep 内 error 对应的回调函数; onmessage:接收到服务端返回的数据,可以先根据自身业务做一些预处理,比如我就根据不同的数据类型进行了数据解析的预处理,之后再触发 dep 内 message 对应的回调函数并传入处理过后的数据。

subscribe:订阅 WebSocket 事件,传入事件类型并须是 EventTypes 内的类型之一,第二个参数则是回调函数; sendMessage:同样的,我们在给服务端发送数据之前也可以根据自身业务做一些预处理,比如我将需要转成 JSON 的数据,在这里统一转换后再发送给服务端; closeSocket:关闭 WebSocket 连接; resetHeartCheck:重置心跳检测定时器。

LICENSE

MIT

webSocketUtil

WebSocket 封装