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

ertc-miniprogram

v0.0.6

Published

## 一、简介

Readme

微信小程序音视频 SDK 接入文档

一、简介

ertc-miniprogram 基于微信小程序提供的 live-player 和 live-pusher 组件,提供多人音视频通话能力,主要提供以下 API:

  • 初始化
  • 加入房间 (enterRoom)
  • 离开房间 (leave)
  • 发布音视频流 (pushStream)
  • 停止发布流 (stopPushStream)
  • 订阅远端视频流 (pullPeerStream)
  • 停止订阅远端视频流 (stopPullPeerStream)
  • 订阅房间内所有成员音频 (pullPeerAllAudioStream)
  • 停止订阅房间内所有成员音频 (stopPullAllPeerAudioStream)
  • 暂停订阅指定端音频 (pullPeerAudioStream)
  • 恢复订阅指定端音频 (pullPeerAudioStream)
  • 房间内信息监听事件 (onRoomInfoChange)
  • 获取房间内信息 (getRoomInfo)
  • 房间内状态变更监听事件 (onRoomStateChange)
  • 房间内错误事件监听 (handleError)

二、API 详情

1、初始化

**初始化对象,所有 API 的调用均依赖初始化实例。**目前仅支持通过内部引入的方式导入。

import ERTC_MINIPROGRAM from "ertc-miniprogram";
let eRtc = null;

eRtc = new ERTC_MINIPROGRAM({
  handleError: this.handleError,
  onRoomInfoChange: this.onRoomInfoChange,
  onRoomStateChange: this.onRoomStateChange,
});

2、加入房间 (enterRoom)

推流、拉流均需要先加入房间

eRtc
  .enterRoom({
    accessToken,
    appId,
    roomId,
    customId,
  })
  .then((res) => {
    // enterRoom:success
  })
  .catch((err) => {
    // enterRoom:fail: msg
  });

3、离开房间 (leave)

当通过 handleError 事件监听到 wesocketConnectError 类型的事件后需要关闭所有推、拉流窗口

eRtc
  .leave()
  .then((res) => {
    // leaveRoom:success
  })
  .catch((err) => {
    // leaveRoom:fail
  });

4、发布音视频流 (pushStream)

调用该接口时,您可以通过设置不同的参数(1-视频流,2-音频流,3-音视频流),推对应的流。如果您需要切换不同类型的流,您需要先调用(stopPushStream)方法停止当前流的推送。我们仅支持一个推流窗口推流。

eRtc
  .pushStream(3)
  .then((res) => {
    // 1-视频流,2-音频流,3-音视频流

    if (res) {
      // res为推流地址,您可将该地址放入live-pusher组件中设置autopush属性自动推流
      // this.setData({
      // pushUrl: res,
      // pushVideo: true,
      // pushAudio: true,
      // })
    }
  })
  .catch((err) => {
    // pushStream:fail: msg
  });

5、停止发布流 (stopPushStream)

eRtc
  .stopPushStream()
  .then((res) => {
    // stopPushStream:success
  })
  .catch((err) => {
    // pushStream:fail msg
  });

6、订阅远端视频流 (pullPeerStream)

我们的音频流采用房间内混音模式,因此,房间内所有成员的音频可以通过【pullPeerAllAudioStream】API 获取,通过该接口获取成员视频流。

在实际使用场景中,您可以通过【onRoomInfoChange】监听到【stram-added】state 类型,订阅远端流

eRtc
  .pullPeerStream(peerCustomId, streamType)
  .then((res) => {
    // peerCustomId-远端customId,streamType-远端流类型

    if (res) {
      // res为拉流地址,您可将该地址放入live-player组件中进行拉流
      // 因房间内存在多个用户不同窗口的拉流,因此建议通过wx.createLivePlayerContext(id, this)方法对各个拉流窗口构造实例
      // const playcontext = wx.createLivePlayerContext(id, this)
    }
  })
  .catch((err) => {
    // pullPeerStream:fail msg
  });

7、停止订阅远端视频流 (stopPullPeerStream)

eRtc
  .stopPullPeerStream(peerCustomId, streamType)
  .then((res) => {
    // peerCustomId-远端customId,streamType-远端流类型
    // stopPullPeerStream:success
  })
  .catch((err) => {
    // stopPullPeerStream:fail msg
  });

8、订阅房间内所有成员音频 (pullPeerAllAudioStream)

eRtc
  .pullPeerAllAudioStream()
  .then((res) => {
    if (res) {
      // res 房间内所有成员音频流地址
    }
  })
  .catch((err) => {
    // pullPeerAllAudioStream:fail msg
  });

9、停止订阅房间内所有成员音频 (stopPullAllPeerAudioStream)

eRtc.stopPullAllPeerAudioStream().then(res => {

    if (res) {
        // pullPeerAllAudioStream:success
    }
}).catch(err => {
    // pullPeerAllAudioStream:fail msg
})

10、暂停订阅指定端音频 和 恢复订阅指定端音频 (pullPeerAudioStream)

您需要先拉取房间内所有成员音频,然后逐个对各个端音频进行暂停和恢复

eRtc
  .pullPeerAudioStream(peerCustomId, pull)
  .then((res) => {
    // mpeerCustomId-指定端customId, pull - true表示恢复,false-表示暂停

    if (res) {
      // pullPeerAudioStream:success
    }
  })
  .catch((err) => {
    // pullPeerAudioStream:fail msg
  });

11、房间内信息监听事件 (onRoomInfoChange)

房间状态改变时会触发,其中的 state 会将房间状态抛出。 可通过绑定 onRoomInfoChange,当 state 状态发生变化时自动抛出,也可通过getRoomInfo方法自动获取。

onRoomInfoChange 触发时间节点:websocket 返回以下信令发生变化时,均会抛出

eRtc.on("onRoomInfoChange", (state, roomInfo, result) => {});

| 序号 | 事件 | 接口描述 | | :--: | :------------: | :---------------------------------------------------------------------: | | 1 | stream-added | 房间内远端有音视频流加入。streamtype: 1 大流 2 音频 4 小流 8 屏幕共享流 | | 2 | stream-removed | 房间内远端有音视频流离开 | | 3 | clientJoin | 远端有用户加入房间 | | 4 | clientLeave | 远端有用户离开房间 | | 5 | error | 表示错误码 |

房间信息数据结构

roomState 结构 {

​	state : number, // 房间状态

​	push_rtmp: string // 推流地址

​	persons: Array, // 房间所有成员状态的数组,一个Person对象代表一个成员。

}

Person 结构 {
    id: string, // 成员clientId
    astate: number, // 0 开起,1 关闭,2 禁用
    vstate: number, // 0 开起,1 关闭,2 禁用
    streams: Array<StreamInfo>, // 通过该地址,可播放该成员的流,目前只有一路
    self: boolean, // 如果是自己这个属性为true, 其他人为false。
}

StreamInfo 结构 {
    stream_type: int, //流类型,1 大流 2 音频  8 屏幕共享流
    angle: number, //角度
    codec: number, // 编码类型
    fps: number, // 帧率
    rtmp: string,// 由内部控制,不需要使用,使用Person结构下的RTMP地址即可。
    state: null, // 预留字段
}

12、房间内错误事件监听 (handleError)

当房间内发生错误时,会通过 handleError 返回错误

eRtc.on('onHandleError', (err) => {

})

| retcode | msg | | :------ | :--------------------------- | | 6001 | 参数错误 | | 6002 | 获取房间信息错误 | | 6003 | 入会参数查询失败 | | 6004 | 无可用服务 | | 6005 | 获取 websocket 地址失败 | | 6006 | websocket 连接失败 | | 6007 | 服务异常(返回服务异常错误) | | 6008 | websocket 连接错误 | | 6009 | websocket 连接断开 | | 6010 | 用户已离开房间 | | 6011 | 正在进行重连 |