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

zqdemo123

v1.0.24

Published

- npm 方式:

Downloads

31

Readme

使用方法

引入方式

  • npm 方式:

安装:

npm i zqdemo123

调用:

import ChatRoomSDK from 'zqdemo123'

let chat = new ChatRoomSDK()

API

WebSocket 初始化: initWS(url, msgCallback, openCallback, errCallback, closeCallback)

demo:
// 参数说明: url: WebSocket url  msgCallback: WebSocket监听消息的回调, openCallback: 连接成功的回调, errCallback: 断开连接的回调, closeCallback: 关闭连接的回调)
chat.initWS(
  'wss://chat.wolover.cn/chat_by_carplate',
  (res) => {
    console.log(res) // res为WebSocket里onMessage接收到的消息
  },
  () => {
    console.log('连接成功')
  },
  () => {
    console.log('断开连接')
  },
  () => {
    console.log('连接已关闭')
  }
)

res 参数说明:

{
    current_group_data,     // 当前所处群组的成员数据
    data,                   // 所有数据,包括群组列表以及群组内成员数据
    dev_group,              // 当前所处群组
    dev_id,                 // 当前群组的调度平台
    msg_type,               // 消息类型
}

获取麦克风权限: tryGetPermission()

demo:
//  调用initWS()方法默认调用tryGetPermission()方法
chat.tryGetPermission()

检查是否有权限: checkPermission()

demo:
chat.checkPermission()
  • 返回值: Boolean类型

新的语音消息到来时的回调: setAudioMsgRecvCallback(callback)

demo:
chat.setAudioMsgRecvCallback((e) => {
    console.log(e)  // e为语音消息数据
})

获取所有设备当前状态: getAllDevStatus()

demo:
chat.getAllDevStatus().then(res => {
    console.log(res) // res为请求成功的返回值
})
  • 返回一个Promise,需要调.then方法

创建群组,邀请设备成员并进入群组: addGroupAndEnter(car_plates)

demo:
// car_plates: 传入数据类型为数组,数组元素为设备的car_plate字段元素 返回一个Promise,需要调.then方法
// 成员邀请要求: 每个成员需要满足: 1.在线(is_online = true) 2.当前设备没有被其他人占用(is_busy = false)
// 调用本方法前,先调用getAllDevStatus()获取所有设备当前状态,传入合要求的car_plate数组
chat.addGroupAndEnter(['豫AXXX', '豫AXXY']).then(res => {
    console.log(res) // res为传入参数之后的返回值
})

开始录音: startRecord(callback)

demo:
// 参数说明:
// callback: 开始录音后的回调
chat.startRecord((res) => {
    console.log(res)
})

结束录音并发送语音消息: endRecord(callback)

demo:
// 参数说明:
// callback: 结束录音后的回调
chat.endRecord((res) => {
  console.log(res) // res为结束录音后接收到的数据
})

res参数说明:

{
    msg_type: 'new_audio_data',  // 消息格式,当为new_audio_data则说明该数据是一条语音
    from_dev: 'WS',    
    from_dev_name: '我',
    arrayBuffer,		// 语音buffer格式
    time		// 语音时长
}

发送语音消息: sendAudioMsg(base64String, callback)

demo:
// 参数说明: 
// base64String: 语音数据 base64 字符串,可通过 arrayBufferToBase64()方法将 ArrayBuffer 格式转为 base64
// callback: 发送语音的回调
chat.sendAudioMsg(base64, (res) => {
  console.log(res) // res为发送语音的回调,显示是否成功
})

播放录音: playAudioMsg(audioMsg, callback)

demo:
// 参数说明:
// audioMsg: 播放的语音数据(类型: ArrayBuffer格式或者base64字符串)
// callback: 播放结束的回调
chat.playAudioMsg(audioMsg, () => {
    console.log('播放结束')
}) 

ArrayBuffer转base64方法: arrayBufferToBase64()

demo:
chat.arrayBufferToBase64(buffer)
  • 返回一个base64字符串

base64转ArrayBuffer方法: base64ToArrayBuffer()

demo:
chat.base64ToArrayBuffer(base64)
  • 返回一个ArrayBuffer

销毁连接 并退出群组: destroyConnect()

demo:
chat.destroyConnect()