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

jinpai-virtual

v0.0.1

Published

a hekr virtual device

Downloads

2

Readme

virtual

使用示例demo

Browser

// 独立设备
const independent = {
  devTid: '01_ea36eba5dcb422848aaeeba20ef11',
  token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNDI1NTE3Mjc4MSIsInBpZCI6IjAwMDAwMDAwMDAwIiwiZW50IjoiMDE0OTA0NTY2MzQiLCJ0eXBlIjoiV0VCIiwiZXhwIjoxNTE3MzYzMTE1LCJqdGkiOiI3N2MxOWRjYS05ZTkzLTRhNTAtYTRkZC1jMjMyYzkxMTBhNGUiLCJyb2xlcyI6WyJlbnRlcnByaXNlIl19.NpL1G5SlVEnekFoKj1fS9T_WQOwuK1yWGoC6WtT79O-ZA-ioMcrQ4EerTvo3m2EeV0KSFHkvUKjUfdTxofrnYg=='
}

// 网关子设备
const gateway = {
  devTid: '270fd8eadad140a59df6272349838c9f',
  subDevTid: '01_76bbe85247ff2c4152167d3486d52',
  token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNDI1NTE3Mjc4MSIsInBpZCI6IjAwMDAwMDAwMDAwIiwiZW50IjoiMDE0OTA0NTY2MzQiLCJ0eXBlIjoiV0VCIiwiZXhwIjoxNTE3MzYzMTE1LCJqdGkiOiI3N2MxOWRjYS05ZTkzLTRhNTAtYTRkZC1jMjMyYzkxMTBhNGUiLCJyb2xlcyI6WyJlbnRlcnByaXNlIl19.NpL1G5SlVEnekFoKj1fS9T_WQOwuK1yWGoC6WtT79O-ZA-ioMcrQ4EerTvo3m2EeV0KSFHkvUKjUfdTxofrnYg=='
}

const virtual1 = new Virtual(independent)
const virtual2 = new Virtual(gateway)

// 虚拟设备登陆成功后执行
virtual1.ready(() => {
  console.log(virtual1)
})

virtual1.on('receive', data => {
  console.log(data)
})

virtual1.on('send', data => {
  console.log(data)
})

Node

const WebSocket = require('ws')

// 加载到全局,否者会报错
global.WebSocket = WebSocket

// 独立设备
const independent = {
  devTid: '01_ea36eba5dcb422848aaeeba20ef11',
  token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNDI1NTE3Mjc4MSIsInBpZCI6IjAwMDAwMDAwMDAwIiwiZW50IjoiMDE0OTA0NTY2MzQiLCJ0eXBlIjoiV0VCIiwiZXhwIjoxNTE3MzYzMTE1LCJqdGkiOiI3N2MxOWRjYS05ZTkzLTRhNTAtYTRkZC1jMjMyYzkxMTBhNGUiLCJyb2xlcyI6WyJlbnRlcnByaXNlIl19.NpL1G5SlVEnekFoKj1fS9T_WQOwuK1yWGoC6WtT79O-ZA-ioMcrQ4EerTvo3m2EeV0KSFHkvUKjUfdTxofrnYg=='
}

const virtual1 = new Virtual(independent)

// 虚拟设备登陆成功后执行
virtual1.ready(() => {
  console.log(virtual1)
})

virtual1.on('update', (nState, oState) => {
  console.log('update:----------------------------')
  console.log(nState, oState)
  console.log('-----------------------------------')
})

virtual1.on('receive', data => {
  console.log(data)
})

virtual1.on('send', data => {
  console.log(data)
})

Options

网关子设备,devTid为网关的devTid,subDevTid为子设备的devTid,token是用户调用云端API时用到的token

// 值为不为undefined的都是默认值
new Virtual({
  token: undefined, // 用户token
  devTid: undefined, // 设备devTid
  subDevTid: undefined, // 子设备devTid
  debug: true, // 是否为网页debug模式,否则为预览模式
  heartbeat: 7000, // 心跳间隔
  reconnect: false, // ws断开自动重连
  delay: 0, // 上报帧延时时间,模拟网络延时
  report: false, // 状态改变后是否上报包含参数的上报帧(非关联上报帧)
  URL: {
    console: 'https://console-openapi.aihomi.com', // console api地址
    user: 'https://user-openapi.aihomi.com', // user api地址
    ws: 'wss://asia-dev.aihomi.com:184' // ws地址
  }
})

Methods

| 名称 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | ready | 虚拟设备登录成功后的回调 | 回调函数 | 返回Promise | | receive | 传入数据,模拟云端发送数据到设备 | 发送的数据 | - | | send | 发送数据到云端 | 发送的数据 | - | | setState | 设置内部状态值 | 状态数据对象 | - | | connect | 建立ws连接 | - | - | | close | 关闭ws连接 | - | - |

  • ready:设备登录成功回调,返回Promise
virtual.ready(() => {
  // 设备已经登录成功
  // do something
})
  • receive:传入数据,模拟云端发送数据到设备,无返回值
// data为云端通过ws返回的数据经JSON.parse序列化后的数据
virtual.receive(data)
  • send:发送数据到云端,无返回值
// 可以把data看作是websocket通信中的{params: { data }}中的data部分的数据
const data = {
  cmdId: 1,
  sw: 1,
  light: 100
}
virtual.send('devSend', { data })
  • setState:更新设备状态state,无返回值
// 更新state中的数据
// 更新策略和react的setState是一样的
virtual.setState({ data })
  • connect:建立WebSocket连接,如果已经有可用连接就不再创建新的

  • close:关闭WebSocket连接,无返回值

Events

| 名称 | 说明 | 回调参数 | | --- | --- | --- | | receive | 接收到云端数据事件 | 接收到的数据 | | send | 发送到云端数据事件 | 发送的数据 | | update | state改变更新事件 | nState:最新的状态数据,oState:前一个状态的数据 | | addSubDevResp | 子设备添加成功时的事件 | 虚拟设备对象,响应帧内容 | | reportSubDevInfoResp | 子设备登录成功时的事件 | 虚拟设备对象,响应帧内容 |

TODOS

  • [ ] 48协议、新48协议的5、6帧类型没有解析
  • [ ] 网关子设备登录之后添加事件

网关还是让所有的都去启动一个virtual类,然后把所有的都在发送到网关设备通道中