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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ertc-web-call

v1.0.0

Published

> 本教程基于 ertc-web-call SDK 1.x 版本

Readme

web S10 视频通话 SDK 接入引导

本教程基于 ertc-web-call SDK 1.x 版本

视频通话功能是萤石屏类设备(比如 S10/RK3 等)产品中的一项重要功能,旨在为用户提供便捷的远程视频通话体验。用户可以通过手机或其他设备与摄像头进行实时的视频对话。

快速接入

1. 您可以在项目中使用 npm 安装 ertc-web-call

npm install ertc-web-call

2. 在项目中引入

import ERTCCall from 'ertc-web-call'

const ertcCall = new ERTCCall()

3. 监听事件

// xxx.html
<div>
  <video id="remote-element"></video>
  <video id="local-element"></video>
</div>

// xxx.js

/**
* SDK事件监听
*/
// 监听设备媒体流
ertcCall.on(ERTCCall.EVENT.REMOTE_STREAM_AVAILABLE, ({ streamtype, stream }) => {
  console.log("获取到远端媒体流");
  if ([ERTCCall.STREAM_TYPE.AUDIO_ONLY, ERTCCall.STREAM_TYPE.VIDEO_ONLY].includes(streamtype)) {
    ERTCCall.attachMediaStream("#remote-element", stream);
  }
});

// 监听本地媒体流
ertcCall.on(ERTCCall.EVENT.LOCAL_STREAM_AVAILABLE, ({ streamtype, stream }) => {
  console.log("获取到本地媒体流");
  if (streamtype === ERTCCall.STREAM_TYPE.VIDEO_ONLY) {
    ERTCCall.attachMediaStream("#local-element", stream);
  }
});

// 监听呼叫状态变化
ertcCall.on(ERTCCALL.EVENT.STATUS_CHANGE, (status) => {
  console.log("状态改变", status); // init:未呼叫,calling:正在呼叫中,talking:通话中
  // 更改业务层状态展示
})

// 监听呼叫超时
ertcCall.on(ERTCCALL.EVENT.CALL_TIMEOUT, () => {
  console.log("呼叫超时");
  // 执行业务层逻辑
})


/**
* 业务层设备推送的webhook消息接收
*/
// 设备拒接、设备忙线被占用
callback = () => {
  // callback只是示例代码,指代设备拒接的回调函数,并非sdk内部函数

  ertcCall.reset() // sdk感知不到设备的拒绝和忙线,所以需要在此处重置sdk的呼叫状态
}

4. 发起呼叫

客户端(web)往web端主动发起呼叫,可能存在拒接、超时的情况。拒接需要通过客户服务端返回,超时默认20000ms,可在事件中监听超时。

const initParams = {
  accessToken: "",
  appId: "",
  account: "",
  deviceSerial: "",
  strRoomId: "",
  resourceToken: "",
  deviceResourceToken: "",
  timeout: '',
}

ertcCall.makeCall(initParams).then((res) => {
    message.success("呼叫发起成功");
    console.log("呼叫发起成功:", res);
  }).catch((err) => {
    message.error(`呼叫发起失败`);
    console.log("呼叫发起失败:", err);
  });

| 参数 | 参数含义 | 补充说明 | 数据类型 | 示例 | 是否必填 | | ------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------ | -------- | | accessToken | 开放平台应用鉴权凭证 | 需要在 开放平台控制台 创建实时音视频项目,对应创建的项目 id | string | at.xxxxxxxxxxxx-xxxxxxxxxx-xxxxxxx-a3gi2pj | 是 | | appId | 应用 id | 您可以在控制台实时音视频 中找到您的 appId,如果没有,则单击“创建项目”按钮创建一个新的应用 | string | ebadss852xxxxxxxxxxxxxxcb4192d3c781 | 是 | | account | 用户id | 视频通话用户id/用户名,避免重复,由客户服务端管理生成并传给web | string | "112233" | 是 | | deviceSerial | 设备序列号 | - | string | - | 是 | | strRoomId | 房间 id | roomId/房间号/会议ID,视频通话房间号,由客户服务端管理生成并传给web | string | - | 是 | | resourceToken | 用户资源token | 用于客户端(web)入会权限校验,不是accessToken,由客户服务端管理生成并传给web,参考Java SDK生成:https://open.ys7.com/help/1873 | string | - | 是 | | deviceResourceToken | 设备资源token | 服务端使用,用于邀请设备入会,并做权限校验,不是accessToken,由客户服务端管理生成并传给web,参考Java SDK生成:https://open.ys7.com/help/1873 | string | - | 是 | | timeout | 呼叫超时时间 | 一般通过接口查询设备超时时间,获取后进行设置,不传则默认20秒 | number | 20000 | 否 |

5. 取消呼叫

在呼叫接口发起,到设备端接听/拒接的过程中,可以通过取消呼叫来主动结束呼叫。

const initParams = {
  accessToken: "",
  appId: "",
  account: "",
  deviceSerial: "",
  strRoomId: "",
  resourceToken: "",
  deviceResourceToken: "",
}
ertcCall.cancleCall(initParams).then(() => {
    console.log("取消呼叫成功");
  }).catch((err) => {
    console.log("取消呼叫发起失败", err);
  });

6. 接听

设备端往客户端(web)呼叫,客户服务端接收到通知后,将房间号传给客户端(web),生成 resourceToken 后,调用接听接口,加入房间,实现通话。

const initParams = {
  appId: "",
  account: "",
  strRoomId: "",
  resourceToken: "",
}
ertcCall.acceptCall({
    resourceToken,
    appId,
    strRoomId,
    account,
  })
  .then(() => {
    message.success("接听调用成功");
    console.log("🚀 ~ ERTCCALL ~ acceptCall ~ 接听调用成功");
  })
  .catch((err) => {
    message.error(`接听调用失败`);
    console.log("🚀 ~ ERTCCALL ~ acceptCall ~ 接听调用失败", err);
  });

7. 拒接

设备端往客户端(web)呼叫,客户端拒接。

const initParams = {
  accessToken: "",
  appId: "",
  account: "",
  deviceSerial: "",
  strRoomId: "",
  resourceToken: "",
}
ertcCall.rejectCall(initParams)
  .then((res) => {
    console.log("拒接成功");
  })
  .catch((err) => {
    console.log("拒接失败", err);
  });

8. 挂断

在通话通过中调用,主动挂断电话,双方退出房间。

ertcCall.hangup().then(() => {
    console.log("挂断成功");
  }).catch((err) => {
    console.log("挂断失败", err);
  });

9. 设置音视频参数

设置客户端(web)发送的音视频参数,包括音频参数、视频参数等。在发起呼叫之前调用才生效。

ertcCall.setProfile({
  cameraId, // 摄像头deviceId
  microphoneId, // 麦克风deviceId
  width, // 分辨率 宽
  height, // 分辨率 高
  frameRate, // 最大视频帧率
  bitrate, // 最大视频码率,单位:kbps
})