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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chat-sdk-real-time

v1.0.2

Published

实时录音

Readme

使用方法

引入方式

  • npm 方式:

安装:

npm i chat-sdk-real-time

调用:

import ChatRealTime from 'chat-sdk-real-time'

let chat = new ChatRealTime()

新版本说明

新版本改为实时语音发送,原理为用户开始录音时就开启录音,并将录音数据切分为固定大小的录音片段发送至后台,录音结束后手动发送一个空的录音数据作为结束标识符;新增 msg_id 字段作为身份的唯一标识符,通过该字段判断语音片段的发送者,每次发送的 msg_id 都会随机生成。

API

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

demo:
// 参数说明: url: WebSocket url   id: 用户输入的管理员信息  msgCallback: WebSocket监听消息的回调, openCallback: 连接成功的回调, errCallback: 断开连接的回调, closeCallback: 关闭连接的回调)
// 用户输入的管理员信息会拼接到WebSocket url的后边
chat.initWS(
  'wss://chat.wolover.cn/my_dev_id/',
  'WSadmin2',
  res => {
    console.log(res) // res为WebSocket里onMessage接收到的消息
  },
  () => {
    console.log('连接成功')
  },
  () => {
    console.log('断开连接')
  },
  () => {
    console.log('连接已关闭')
  }
)

res 参数说明:

{
    current_group_data,     // 当前所处群组的成员数据
    data,                   // 所有数据,包括群组列表以及群组内成员数据
    dev_group,              // 当前所处群组
    dev_id,                 // 当前群组的调度平台
    msg_type,               // 消息类型
    data_type,              // 新版本实时语音的标识类型为3
}

获取麦克风权限: tryGetPermission()

demo:
chat.tryGetPermission()

检查是否有权限: checkPermission()

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

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

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

开始录音: startRecord(callback)

demo:
// 参数说明:
// res: 开始录音后的返回值
chat.startRecord(res => {
  if (res.type === 'success') { // 有麦克风权限
    console.log('开始录音成功')
  } else if (res.type === 'error') {  // 无麦克风权限
    console.log('开始录音失败', res.msg)
  }
})

结束录音: endRecord(callback)

demo:
// 参数说明:
// res: 结束录音后的返回值
chat.endRecord((res) => {
  console.log(res) // res内有msg_id字段,为身份标识
})

语音片段放入播放队列进行播放: listenVoicePlayingAddChunk(b64_data)

demo:
// 备注:需和WebSocket里onMessage方法搭配使用,当msg_type == "new_audio_data"和data_type === 3时,并且需要判断b64_data != '',将录音片段的b64_data传入本方法
// 注意:新版本返回的字段中新增了msg_id字段,该字段为发送语音对象的唯一身份标识,通过该字段来判断该条语音片段是哪个对象发的,用户自行判断逻辑
// 参数说明: b64_data为websocket返回录音片段的base64字符串
chat.listenVoicePlayingAddChunk(b64_data)

创建新群组: addGroup(group_name)

demo:
// 参数说明:
// group_name: 群组名
chat.addGroup('新群组').then(res => {
  console.log(res) // res为请求成功的返回值
})

删除群组: delGroup(group_name)

demo:
// 参数说明:
// group_name: 群组名
chat.delGroup('群组').then(res => {
  console.log(res) // res为请求成功的返回值
})

编辑群组: renameGroup(group_name, new_group_name)

demo:
// 参数说明:
// group_name: 老名称; new_group_name: 新名名称
chat.renameGroup('老名称', '新名称').then(res => {
  console.log(res) // res为请求成功的返回值
})

切换当前所在群组: setCurrentGroup(group_name)

demo:
// 参数说明:
// group_name: 群组名
chat.setCurrentGroup('群组A')

新增管理人员: addWsDev(dev_id, dev_name)

demo:
// 参数说明:
// dev_id: 管理人员ID,必须是WS开头的英文+数字的字符串。  总长度是6-11位。不能含有空格
// dev_name: 管理人员昵称,必须是2-10位长度的中文/英文/数字/下划线 的字符串, 不能含有空格
chat.addWsDev('WSadmin13', '系统超管13').then(res => {
  console.log(res) // res为请求成功的返回值
})

查询所有设备成员: getDevList()

demo:
chat.getDevList().then(res => {
  console.log(res) // res为请求成功的返回值
})

邀请设备成员到群组(可单个或多个): addMembersToGroup(group_name, dev_ids)

demo:
// 参数说明:
// group_name: 群组名
// dev_ids: dev_id(数组格式)
// dev_id从getDevList()方法中获取
chat.addMembersToGroup('群组名', ['4001', '4002']).then(res => {
  console.log(res) // res为传入参数之后的返回值
})

移除成员(把设备从群组中移除): delMember(dev_id, group_name)

demo:
// 参数说明:
// dev_id: 成员设备ID
// group_name: 群组名
chat.delMember('4001').then(res => {
  console.log(res) // res为传入参数之后的返回值
})

编辑成员(修改设备名称): renameMember(dev_id, dev_name)

demo:
// 参数说明:
// dev_id: 成员设备ID
// dev_name: 成员设备名称
chat.renameMember('4001', '名称').then(res => {
  console.log(res) // res为传入参数之后的返回值
})

删除设备/管理人员: delDev(dev_id)

demo:
// 参数说明:
// dev_id: 成员设备ID
chat.delDev('4001').then(res => {
  console.log(res) // res为传入参数之后的返回值
})

通道标定(设置某设备所归属的所有群组): setDevGroupsInfo(dev_id, groups)

demo:
// 参数说明:
// dev_id: 成员设备ID
// groups: 群组名的数组
chat.setDevGroupsInfo('4001', ['群组A', '群组B']).then(res => {
  console.log(res) // res为传入参数之后的返回值
})

一键配置通道(所有群成员设备的通道 0 将指向本群): activeGroupMembers(group_name)

demo:
// 参数说明:
// group_name: 群组名
chat.activeGroupMembers('群组A').then(res => {
  console.log(res) // res为传入参数之后的返回值
})