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

yskj-mqtt

v1.1.4

Published

元素科技mqtt层封装

Downloads

7

Readme

最新版本 V1.1.4

更新说明(V1.1.4)
1. 添加mqtt心跳
更新说明(V1.1.3)
1. 删除重连次数大于10关闭mqtt的代码
更新说明(V1.1.2)
1. 新增接收消息回调topic参数
2. 主题去重默认主题
3. 整理多余的代码
更新说明(V1.1.1)
1. 修改多个订阅主题时,自定义的主题为用户方传入,不手动拼接clintId
更新说明(V1.1.0)
1. 修改接收参数回调少写了一个this
更新说明(V1.0.9)
1. 取消clintId参数,由底层维护此字段
2. 调整theme参数集合为非必传,默认订阅'ys/web'主题
更新说明(V1.0.8)
1. 修复关闭mqtt时不传递回调函数报错问题
更新说明(V1.0.7)
1. 新增closeMqtt回调函数
2. 修复连接成功时返回的主题类型为undefined
更新说明(V1.0.6)
1. 新增userName字段 
2. 解决已连状态下重连bug

基本用法

    options = {
        connectTimeout: 4000,
        clientId: 'wb_' + 111111,
        token: 'xxx',
        clean: true,
        url: 'ws://192.168.38.218:28083/mqtt',
        theme: [{
            type: 'ys/web'
        }]
    }
    this.myMqtt = new mqtt(options)
    this.myMqtt.on('connect', (data) => {
        console.log('订阅成功', data)
    })
    this.myMqtt.on('message', (data) => {
        console.log('成功接收消息', data)
    })

options说明

| 配置项|是否必传|类型|默认值|说明| |-|:-:|:-:|:-:|:-:| | clientId | 否 | String | '' | 订阅mqtt的唯一用户值, * V1.0.9取消 | | connectTimeout | 否 | Number | 4000 | 设置连接超时时间 | | token | 是 | String | '' | 用户登录mqtt令牌 | | clean | 否 | Boolean | true | 是否在重连恢复时订阅 | | url | 是 | String | '' | 连接mqtt地址 | | userName | 否 | String | 'web_user' | 用户名 | | theme | 否 | Array | [obj] | 订阅的主题,默认订阅'ys/web'主题。格式为json数组,配置项见下文theme配置, * V1.0.9下为必传 |

theme配置(支持扩展自定义值,会在连接成功回调返回)

| 配置项|是否必传|类型|默认值|说明| |-|:-:|:-:|:-:|:-:| | type | 是 | String | '' | 主题类型,最后不要以'/'结尾,切记!!! | | ... | 否 | String | '' | 扩展的自定义的值 |

回调函数

所有的回调函数是在on中接收

| 函数名|说明| |-|:-| | connect | 成功连接mqtt时返回,返回参数为当前订阅的主题类型 | | message | mqtt成功下发数据时返回,返回的为json对象 | | reconnecting | 正在重新连接时返回,返回参数为:第几次重新连接 | | error | mqtt错误时返回 |

事件

eg: this.myMqtt.closeMqtt()

| 事件名|事件说明| |-|:-| | closeMqtt[callback] | 断开mqtt | | reconnect | 手动重连mqtt |