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

cmdsrv-sdk

v1.0.0

Published

github: https://github.com/eyasliu/cs

Downloads

1

Readme

Command Service JSSDK

github: https://github.com/eyasliu/cs

开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单

JSSDK 支持 http 和 websocket 连接

install

via npm:

npm install -S cmdsrv-sdk

via yarn:

yarn add cmdsrv-sdk

via script:

<script src="./cssdk.js"></script>

Usage

const wsUrl = 'ws://localhost:8080/ws'
const sseUrl = 'http://localhost:8080/sse'
const cs = new CS(wsUrl)

cs.resetUrl(sseUrl) // reset endpoint url


cs.on('cs.connected', e => {}) // 连接建立时触发
cs.on('cs.closed', e => {}) // 连接关闭时触发
cs.on('cs.message', e => {}) // 收到任意数据时触发

cs.on('register', data => {}) // 监听 cmd: register 命令的响应

cs.send('register', {uid: 10001}) // 发送命令和数据消息

cs.destroy() // 销毁连接

API

方法

CS(url, options?)

构造函数,实例化 CS,

  • url [string, object]连接url,支持 websocket 和 http url,如果为 object,则视为options参数
  • options [object] 配置选项,可选
    • options.url [string] 同上 url 参数
    • options.headers [object] 发起 http 请求和 sse 连接时自定义的 http headers
    • options.withCredentials 发起http请求和sse 连接时是否携带 cookie,默认为 true,如果为 false,则 sse 将不会正常工作
    • options.wsMsgType ['blob', 'text'] websocket 的消息类型,blob 为二进制消息, text 为文本消息
    • options.wsHeartBeatTime [number] websocket 心跳时间

cs.resetUrl(url)

重新设置连接 url,会触发重连

cs.adapterName

返回当前连接的适配器类型, 固定 ws 或者 http

cs.send(command, data?)

往连接发送命令和数据

  • command 命令名称
  • data 发送命令时携带的参数

cs.on(event, handler)

监听事件,事件见下文

cs.destroy()

销毁连接和实例。在实例没有销毁前,如果连接因为意外断开了,会自动重连。如果已经销毁了,则断开连接,并且不再重连。

事件

cs.connected

连接建立成功后触发,即使是因为断线重连时也会触发

cs.closed

连接断开会触发,即使是因为意外断线也会触发

cs.message

收到服务器消息时触发,无论是什么消息。

[command]

监听指定 command 的消息,收到指定的 command 时触发

License

cs is released under the MIT License.

(c) 2020-2021 Eyas Liu [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.