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

@koi-video/voice-realtime-sdk

v3.0.1

Published

Voice realtime ChatClient: REST (webrtc/v1 start/stop) + Web RTC

Readme

@koi-video/voice-realtime-sdk

浏览器端实时语音 SDK:HTTP 会话(/start/stop)配合 Robot-Key / Robot-Token,以及 WebRTC(麦克风、远端音频、流消息)。Agora Web SDK 为本包依赖,随安装一并拉取。

English documentation


Installation

pnpm add @koi-video/voice-realtime-sdk
import { ChatClient, VoiceEvents } from '@koi-video/voice-realtime-sdk';

| 导出 | 说明 | |------|------| | ChatClient | 主客户端。 | | VoiceEvents | 事件名常量(见 Events)。 |


最小流程(方法与事件)

import { ChatClient, VoiceEvents } from '@koi-video/voice-realtime-sdk';

const client = new ChatClient(
  {
    robotKey: process.env.ROBOT_KEY,
    robotToken: process.env.ROBOT_TOKEN
  },
  {
    userName: 'demo-user-1'
  }
);

client.on(VoiceEvents.SESSION_CREATED, ({ sessionId }) => {
  console.log('SESSION_CREATED', sessionId);
});

client.on(VoiceEvents.SESSION_STARTED, ({ sessionId }) => {
  console.log('SESSION_STARTED', sessionId);
});

client.on(VoiceEvents.SESSION_ENDED, ({ sessionId, reason }) => {
  console.log('SESSION_ENDED', sessionId, reason);
});

client.on(VoiceEvents.USER_MESSAGE, ({ sessionId, content, segmentId, raw }) => {
  console.log('user:', content, segmentId, raw);
});

client.on(VoiceEvents.ROBOT_MESSAGE, ({ sessionId, content, segmentId, raw }) => {
  console.log('bot:', content, segmentId, raw);
});

client.on(VoiceEvents.INTERRUPT, ({ sessionId }) => {
  console.log('INTERRUPT', sessionId);
});

client.on(VoiceEvents.AUDIO_MUTED, ({ sessionId }) => {
  console.log('AUDIO_MUTED', sessionId);
});

client.on(VoiceEvents.AUDIO_UNMUTED, ({ sessionId }) => {
  console.log('AUDIO_UNMUTED', sessionId);
});

client.on(VoiceEvents.ERROR, err => {
  console.error(err.code, err.message);
});

client.on(VoiceEvents.ALL, (eventName, data) => {
  console.log('ALL', eventName, data);
});

const sessionId = await client.startVoiceChat();

client.interrupt();
await client.setAudioEnabled({ bool: false });
await client.setAudioEnabled({ bool: true });
await client.stopVoiceChat();

Events

使用 client.on(VoiceEvents.XXX, handler)client.on(VoiceEvents.ALL, (eventName, data) => ...)

VoiceEvents

| 常量 | 触发 / 载荷 | |------|----------------| | SESSION_CREATED | /start 成功且 RTC 就绪 — { sessionId }。 | | SESSION_STARTED | 紧接 SESSION_CREATED,相同 { sessionId }。 | | SESSION_ENDED | 挂断、RTC 断开、远端超时等 — { sessionId, reason }。含 user_stopdisconnectedremote_join_timeoutremote_rejoin_timeout 等。 | | USER_MESSAGE | 流 topic === 'chat',用户 — { sessionId, content, segmentId?, timestamp?, raw }raw 为该条消息的完整服务端 JSON;content / segmentId / timestamp 为便于使用的派生字段。 | | ROBOT_MESSAGE | 流 topic === 'chat',助手 — 同上。 | | AUDIO_MUTED / AUDIO_UNMUTED | setAudioEnabled 之后 — { sessionId }。 | | INTERRUPT | 流 topic === 'interrupt'{ sessionId }。 | | ERROR | 接口 / RTC / 解析错误 — codemessage 等。 | | ALL | 所有事件:(eventName, data)。 |

订阅 ALL 时,第一个参数还可能是 FLOW_DEBUGSIDE_INFOSTREAM_MESSAGE

常见 ERROR.codeHTTP_*NETWORKRTC_ERRORSTREAM_PARSECHAT_ERRORRTC_STOPSTOP_API,以及 REMOTE_JOIN_TIMEOUT(本地 RTC 进房后 15s 内仍无任何远端 user-joined)、REMOTE_REJOIN_TIMEOUT最后一个远端离开后 30s 内无远端再次进房)。


Demo (this repo)

cd packages/voice-realtime-sdk
pnpm install
pnpm demo
pnpm demo:build
pnpm demo:preview

完整示例见 demo/demo/vite.config.js 中可选 HTTPS)。