# @antmedia/webrtc\_adaptor 中文文档

规范地址：https://npmcn.com/package/%40antmedia/webrtc_adaptor/

版本：2\.16\.2
npm 元数据更新时间：2026-08-12T10:15:43.455Z
中文译文更新时间：2026-11-06T06:53:05.870Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40antmedia/webrtc_adaptor
原文对照：https://npmcn.com/package/%40antmedia/webrtc_adaptor/?lang=original
项目主页：https://github.com/ant-media/StreamApp#readme
源码仓库：https://github.com/ant-media/StreamApp

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：9.1 MB，149 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2022-02-24T13:59:38.210Z
- 最新版本发布：2025-12-08T15:18:37.655Z
- 近 30 天下载量：28670（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：220（近 12 个月 3 个）

## 中文简介

网络RTC 用于使用Ant Media Server执行前端的适配器.

## 安装

```sh
npm install @antmedia/webrtc_adaptor
```

也可以使用：`pnpm add @antmedia/webrtc_adaptor`、`yarn add @antmedia/webrtc_adaptor`、`bun add @antmedia/webrtc_adaptor`

## README

# [蚂蚁媒体服务器](https://antmedia.io/) WebRTC 联合来文SDK

在使用Javascript在蚂蚁媒体服务器上发布和播放WebRTC流的WebSocket接口.

详情请访问 [蚁媒.io](https://antmedia.io/)

[![Build Status](https://api.travis-ci.com/ant-media/StreamApp.svg?branch=master)](https://app.travis-ci.com/github/ant-media/StreamApp) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=io.antmedia%3Aant-media-server&metric=alert_status)](https://sonarcloud.io/dashboard?id=io.antmedia%3Aant-media-server)

## 安装

使用 npm :

```shell
$ npm install @antmedia/webrtc_adaptor
```

使用线条 :

```shell
$ yarn add @antmedia/webrtc_adaptor
```

## 所需资源

在开始使用Ant Media Server WebRTC SDK之前,需要发布运行在服务器或本地机器上的Ant Media Server. [快速启动 - 蚂蚁媒体服务器](https://antmedia.io/docs/)

## 使用量

在你的项目中,运行:

```
npm i @antmedia/webrtc_adaptor
```

在你的日记档案里:

#### 初始化 WebRTCAdaptor

```javascript
  // ...
import { WebRTCAdaptor } from '@antmedia/webrtc_adaptor';

const webRTCAdaptor = new WebRTCAdaptor({
    websocket_url: "wss://your-domain.tld:5443/WebRTCAppEE/websocket",
    mediaConstraints: {
        video: true,
        audio: true,
    },
    peerconnection_config: {
        'iceServers': [{'urls': 'stun:stun1.l.google.com:19302'}]
    },
    sdp_constraints: {
        OfferToReceiveAudio : false,
        OfferToReceiveVideo : false,
    },
    localVideoId: "id-of-video-element", // <video id="id-of-video-element" autoplay muted></video>
    bandwidth: int|string, // default is 900 kbps, string can be 'unlimited'
    dataChannelEnabled: true|false, // enable or disable data channel
    callback: (info, obj) => {}, // check info callbacks bellow
    callbackError: function(error, message) {}, // check error callbacks bellow
});
//...
```

在您的剧本的另一部分:

#### 发布

```javascript
// You can start streaming by calling the publish method
webRTCAdaptor.publish(streamId);
```

#### 播放

```javascript
// You can start playing the stream by calling the play method
webRTCAdaptor.play(streamId);
```

## 样本

访问 [样本列表](https://antmedia.io/webrtc-samples/) 看看他们 [源代码](https://github.com/ant-media/StreamApp/tree/master/src/main/webapp)

## 文档

[Javascript SDK 文档](https://antmedia.io/docs/guides/developer-sdk-and-api/sdk-integration/javascript-sdk/)

## 现场直播

你可以检查我们 [现场演示](https://antmedia.io/live-demo)。 。 。 .

## 问题

在 [蚂蚁媒体服务器](https://github.com/ant-media/Ant-Media-Server/issues)

## StreamApp供蚂蚁媒体服务器开发者使用

此寄存器包括了Ant Media Server的默认流流程序. Ant Media 服务器开发者可以将其作为基础应用程序来启动他们的应用程序. 它主要有三个组成部分.

### 联合来文SDK

位于 `src/main/js/` 目录是JS SDK。 它的编译,测试和部署到 `src/main/webapp/js` 目录. 这些出版物已经发表在npmjs.org以及上面提到的.

### 嵌入式玩家

位于 `embedded-player` 是蚂蚁媒体服务器的嵌入式播放器。 它主要用来 [@antmedia/web player(网络游戏)](https://www.npmjs.com/package/@antmedia/web_player) 为默认应用程序提供嵌入式播放器。 编成并部署到 `src/main/webapp/js` 它被使用 被 `src/main/webapp/play.html`

### 马文项目

一般来说,这种repo是一个maven项目,它提供java文件,web.xml和属性文件来创建流程序.

### 如何建设

-   在主目录中, 运行以下命令以安装 npm 包
    
    ```
    npm install
    ```
    
-   到嵌入式玩家安装 npm 套件
    
    ```
    cd embedded-player
    npm install
    ```
    
-   切换到主目录并运行 `redeploy.sh`它汇编和复制js文件到 `src/main/webapp/js`
    
    ```
    ./redeploy.sh
    ```

## 常见问题

### @antmedia/webrtc\_adaptor 是什么？

网络RTC 用于使用Ant Media Server执行前端的适配器\.

### 如何安装 @antmedia/webrtc\_adaptor？

在项目目录运行 npm install @antmedia/webrtc\_adaptor，或使用 pnpm add / yarn add / bun add。

### @antmedia/webrtc\_adaptor 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @antmedia/webrtc\_adaptor 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @antmedia/webrtc\_adaptor 可以商用吗？

@antmedia/webrtc\_adaptor 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @antmedia/webrtc\_adaptor 的下载量有多少？

根据 npm 官方下载统计，@antmedia/webrtc\_adaptor 在 2026/10/06 – 2026/11/04 这 30 天内被下载 28,670 次，日均约 956 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @antmedia/webrtc\_adaptor 还在维护吗？

最新版本 2\.16\.2 发布于 2025/12/08（10 个月前）；至今共发布 220 个版本，其中过去 12 个月发布了 3 个；首次发布于 2022/02/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

