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

yr-panel-sdk

v1.1.11

Published

yr panel sdk

Downloads

9

Readme

一、React Native SDK 模块介绍

通过桥接原生的一些能力,比如网络请求、蓝牙、权限、wifi 等,在此基础上再进行封装,以供 RN 更便捷的使用

二、目录介绍

.
├── README.md
├── bridge                          // 桥接模块
│   ├── bluetooth.js                // 蓝牙
│   ├── brightness.js               // 亮度
│   ├── device.js                   // 设备相关
│   ├── location.js                 // 位置
│   ├── native.js                   // 原生请求、监听封装
│   ├── network.js                  // 网络请求
│   ├── permission.js               // 权限
│   ├── protocol.js                 // 协议
│   ├── router.js                   // 页面跳转
│   ├── tuya.js                     // 涂鸦相关
│   ├── volume.js                   // 声音
│   └── wifi.js                     // wifi
└── yrsdk                           // RN模块
    ├── event.js                    // RN自定义事件
    ├── bluetooth.js                // 蓝牙
    ├── brightness.js               // 亮度
    ├── crypto.js                   // 加密/解密
    ├── device.js                   // 设备相关
    ├── index.js                    // 入口
    ├── location.js                 // 位置
    ├── permission.js               // 权限
    ├── request.js                  // 网络请求
    ├── router.js                   // 页面跳转
    ├── tuya.js                     // 涂鸦相关
    ├── volume.js                   // 声音
    └── wifi.js                     // wifi
    └── yrlog.js                    // log

三、使用

1. 引用

import {
    YRBrightness,
    YRVolume,
    YRPermission,
    YRWifi,
    YRBluetooth,
    YRLocation,
    YRDevice,
    YRRouter,
    YRRequest,
    YREvent,
    YRLog,
    YRCrypto,
    YRTuya
} from 'yr-panel-sdk'

2. YRBrightness

// 获取亮度
const brightness = await YRBrightness.get()

// 设置亮度
YRBrightness.set(brightness)

3. YRVolume

// 获取手机音量
const volume = await YRVolume.get()

// 设置手机音量
YRVolume.set(volume)

4. YRWifi

// 获取wifi状态
const wifiSwitch = await YRWifi.state()

// 获取wifi名称
const wifiName = await YRWifi.getName()

// 获取wifi加密信息
const wifiEncryptString = await YRWifi.encrypt(data)

5. YRDevice

// 获取设备信息
const device = await YRDevice.get()

// 获取app环境
const env = await YRDevice.env()

// 获取baseUrl, 用户相关信息
const base = await YRDevice.base()

// 获取国家码
const countrycode = await YRDevice.countrycode()

// 获取面板信息
const panelInfo = await YRDevice.panelInfo({ panelList: ['app_help_center'] })

// 获取直播截图
const liveShot = await YRDevice.liveShot({ deviceId: '' })

// 通知原生APP
//"event": 设备变化事件类型,事件类型具体如下
//refresh:刷新当前全量设备
//add:添加单个或多个设备
//remove:删除单个或多个设备,如果为空默认全部删除。
//update:更新单个或多个设备,具体更新内容以字段为准,用于更改设备属性。如果是更新整个设备信息,建议使用add。
//"data": 设备数据,设备数据必须有uuid,其他字段根据实际需要添加。字段定义以后台api接口提供的设备数据结构为准,参考device/list或device/info接口。
const notifyNative = await YRDevice.notifyNative({
    event: 'refresh',
    data: { ipc: [{ uuid: '' }], ea: [{ uuid: '' }] }
})

// 获取SD卡信息-p2p
const sdCard = await YRDevice.sdCard({ deviceId: '' })

// 获取Identifier
const identifier = await YRDevice.identifier({ deviceId: '' })

// 显示/隐藏tabbar
const settabbar = await YRDevice.settabbar({ isShow: true / false })

// postEvent广播通知
const postEvent = await YRDevice.postEvent({ type: 'SubscriptionSuccess' })

// android 退出App提示
const backPressed = await YRDevice.backPressed()

// 检查APP升级状态
const checkAppUpgrade = await YRDevice.checkAppUpgrade({
    isShow: true,
    number: 1,
    appleID: 1583154299
})

// 获取红点状态
const getAppUpgradePointStatus = await YRDevice.getAppUpgradePointStatus()

// 设置红点状态(已读)
YRDevice.setAppUpgradePointStatus()

// 调出dokit调试工具(android)
YRDevice.dokit()

// 设置APP缓存密码
const setAppPassword = await YRDevice.setAppPassword({
    account: '',
    password: ''
})
// 获取APP缓存
const getAppCache = await YRDevice.getAppCache()

// 清除APP缓存
const clearAppCache = await YRDevice.clearAppCache()

// 退出登录
const logout = await YRDevice.logout()

6. YRLocation

// 获取定位开关状态
const locationSwitch = await YRLocation.state()

6. YRPermission

const { Permission, Permissions, RESULTS } = YRPermission

// 获取权限列表
const plist = await Permission.get()

// 检查权限
const check = await Permission.check(plist)

// 请求权限
const check = await Permission.request(plist)

7. YRRequest

// get请求
const result = await YRRequest.get('device/newlist', data)

// post请求
const result = await YRRequest.post('chargebee/cancel', data)

// ws 监听
YRRequest.wslisten({ identifier, deviceId, deviceModel }, cb) // 第一个参数必传, cb用来处理设备主动上报的数据

// ws 发送
const d = await YRRequest.wssend(WSMETHOD, cmds)

注意:wslisten必须在wssend之前调用

8. YREvent

// 注册监听
YREvent.listen()

// 移除监听
YREvent.remove()

10. YRBluetooth

// 获取蓝牙状态
const state = await YRBluetooth.state()

// 开始扫描
const startScan = await YRBluetooth.startDevicesDiscovery(data)

// 监听扫描
const onDeviceFound = await YRBluetooth.onDeviceFound((e) => {
    console.log(e)
})

// 移除扫描监听
const removeDeviceFound = await YRBluetooth.removeDeviceFound()

// 停止扫描
const stopScan = await YRBluetooth.stopDevicesDiscovery()

// 创建连接
const createConnection = await YRBluetooth.createConnection(data)

// 监听连接状态改变事件
const onConnectionStateChange = await YRBluetooth.onConnectionStateChange(data, (e) => {
    console.log(e)
})

// 移除连接状态监听
const removeConnectionStateChange = await YRBluetooth.removeConnectionStateChange(data)

// 取消连接
const closeConnection = await YRBluetooth.closeConnection()

// 监听设备通知事件
const notify = await YRBluetooth.notify(data, (e) => {
    console.log(e)
})

// 移除监听设备通知事件
const removeNotify = await YRBluetooth.removeNotify(data)

// 向设备发送数据
const write = await YRBluetooth.write(data)

// 监听设备通知事件
const onStateChange = await YRBluetooth.onStateChange((e) => {
    console.log(e)
})

// 移除蓝牙状态事件
const removeStateChange = await YRBluetooth.removeStateChange()

注意:原生listening必须配合YREvent.listen()使用

11. YRRouter

const { Router, ROUTER } = YRRouter
// 退出面板
Router.pop()

// 回到首页
Router.popRootWiew()

// 页面跳转
// shop页
Router.push(ROUTER.SHOP, data)
// 重置提示页
Router.push(ROUTER.RESET, data)
// 帮助中心页
Router.push(ROUTER.HELPCENTER, data)
// 配网等待页
Router.push(ROUTER.PAIRING, data)
// 反馈页
Router.push(ROUTER.FEEDBACK, data)
...

12. YRLog

YRLog.v('message')

13. YRCrypto

// 加密
YRCrypto.ec(str)
// 解密
YRCrypto.dc(str)

13. YRTrack 埋点

// 流的创建、重启
YRTrack.startFlow()
// 流的断开
YRTrack.endFlow()
// 记录事件
YRTrack.logEvent({ track })
// 上报流
YRTrack.report(type, data)

事件记录原则:
1. 点击事件仅仅是跳转页面的,仅记录页面聚焦事件
2. 点击事件有特殊含义的,记录点击事件和页面聚焦事件

流终止条件:
1. 退出RN面板
2. 杀死APP

// 配网埋点数据结构
{
    "typ": 10050,
    "ts": 1992164510,
    "uuid": "xxxxxx",
    "ext": {
        "evt": "Select_deviceModel",
        "model": "",
        "ts": "",
        "app": "ios",
        "ver": "2.3.4",
        "id": ""
    }
}