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

c-websocket

v1.0.4

Published

uniapp项目,二次封装uni的WebSocket(SocketTask);支持重连,发送心跳,连接多个(微信小程序1.7.0及以上最多5个)

Readme

欢迎使用 c-websocket

注意事项 微信小程序需要wss开头的socket域名,需要配置socket合法域名,具体操作方法:https://mp.weixin.qq.com打开并登录 --->管理 --->开发管理 --->服务器域名 --->修改

微信小程序1.7.0 及以上版本,最多可以同时存在 5 个 WebSocket 连接。1.7.0 以下版本,一个小程序同时只能有一个 WebSocket 连接,如果当前已存在一个 WebSocket 连接,会自动关闭该连接,并重新创建一个 WebSocket 连接。

安装

// npm安装方式,插件市场导入无需执行此命令。插件市场导入地址:https://ext.dcloud.net.cn/plugin?id=22423
npm install c-websocket

使用方法

// 以下导入方式按照安装方式导入,二选一
import Socket from "@/uni_modules/c-websocket";		// 插件市场导入方法
import Socket from "c-websocket";		// npm导入方法

const testSocket = new Socket("testSocket");
testSocket.setHeartbeatParams({
	time: 10000,	// 多少毫秒发送一次心跳
	data: "心跳"		// 心跳发送内容
});
testSocket.setReconnectParams({
	count: 3,		// 重连次数
	time: 3000		// 多少毫秒重连
})
testSocket.connect({
	url: "wss://...",
	heartbeat: {
		open: true,
		time: 30000,
		data: "心跳"
	},
	onOpen: (res) => {
		// socket监听打开,需要处理的逻辑
		testSocket.send("发送一条消息给后端");
	},
	onMessage: (res) => {
		// socket接收服务端的消息,需要处理的逻辑
	},
	onClose: (res) => {
		// socket监听关闭,需要处理的逻辑
	},
	onError: (err) => {
		// socket监听错误,需要处理的逻辑
	}
})
setTimeout(() => {
	testSocket.close((res) => {
		console.log("socket关闭情况:", res);
	});
}, 10000)

API

new Socket(taskName, closeLog)的taskName和closeLog Props

创建对象

|属性|类型|是否必填|说明| |--|--|--|--| |taskName|String|是|创建的socket任务名,唯一| |closeLog|Boolean|否|关闭当前插件里所有的打印(console.log),默认false|

new Socket().setReconnectParams(params: object)的params Props

设置重连socket参数

|属性|类型|是否必填|说明| |--|--|--|--| |isExecute|Boolean|否|是否可以重连,默认true| |count|Number|否|重连次数,默认10| |time|Number|否|多少毫秒重连一次,默认10000|

new Socket().setHeartbeatParams(params: object)的params Props

设置心跳的参数

|属性|类型|是否必填|说明| |--|--|--|--| |open|Boolean|否|是否开启心跳,默认true| |time|Number|否|多少毫秒发送心跳,默认30000| |data|String/ArrayBuffer|否|心跳发送的内容,默认""|

new Socket().connect(params: object)的params Props

创建socket

|属性|类型|是否必填|说明| |--|--|--|--| |url|String|是|uni.connectSocket的url参数| |connectParams|Object|否|uni.connectSocket的参数对象,注:这个属性填写url会覆盖单独设置的url属性| |onOpen|Function|否|SocketTask.onOpen,监听 WebSocket 连接打开事件| |onMessage|Function|否|SocketTask.onMessage,监听 WebSocket 接受到服务器的消息事件| |onClose|Function|否|SocketTask.onClose,监听 WebSocket 连接关闭事件| |onError|Function|否|SocketTask.onError,监听 WebSocket 错误事件|

new Socket().send(data, closeLog)的data和closeLog Props

给服务端发送的函数

|属性|类型|是否必填|说明| |--|--|--|--| |data|String/ArrayBuffer|是|发送给服务端的内容| |closeLog|Boolean|否|关闭当前这次发送内容的打印(console.log)|

new Socket().close(callback)的callback Props

关闭当前socket的函数

|属性|类型|是否必填|说明| |--|--|--|--| |callback|Function|否|执行完的回调|