@antmedia/webrtc_adaptor

中文文档
2.16.2发布于 2025/12/08ISCTypeScriptES Module近 30 天下载 2.9万

WebRTC Adaptor for implementing a front end using Ant Media Server.

原始使用文档
文档目录12 节
  1. Installation
  2. Requirements
  3. Usage
  4. Samples
  5. Documentation
  6. Live Demo
  7. Issues
  8. StreamApp for Ant Media Server Developers
  9. JS SDK
  10. Embedded Player
  11. Maven Project
  12. How to Build

Ant Media Server WebRTC JS SDK

WebSocket interface in publishing and playing WebRTC streams on Ant Media Server using Javascript.

For more information, visit antmedia.io

Build Status Quality Gate Status

Installation

Using npm:

$ npm install @antmedia/webrtc_adaptor

Using yarn:

$ yarn add @antmedia/webrtc_adaptor

Requirements

Before start using Ant Media Server WebRTC SDK, you need a distribution of the Ant Media Server running on a server or local machine. Quick Start - Ant Media Server

Usage

In your project, run:

npm i @antmedia/webrtc_adaptor

Then inside your javascript file:

Initialize the WebRTCAdaptor

  // ...
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
});
//...

In another part of your script:

Publish

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

Play

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

Samples

Visit The Samples List and look at their sources codes

Documentation

Javascript SDK Documentation

Live Demo

You can check our live demo.

Issues

Create issues on the Ant-Media-Server

StreamApp for Ant Media Server Developers

This repository includes the default streaming application for Ant Media Server. Ant Media Server Developer can use it as a base app to get started for their applications. It has mainly three components.

JS SDK

The fileslocated under src/main/js/ directory are the JS SDK. It's compiled, tested and deployed to src/main/webapp/js directory. They been published to npmjs.org as well as mentioned above.

Embedded Player

The files located under embedded-player are the embedded player for Ant Media Server. It mainly use @antmedia/web_player to provide a embedded player for default applications. It's compiled and deployed to the src/main/webapp/js and it's being used by src/main/webapp/play.html

Maven Project

Generally this repo is a maven project and it provides java files, web.xml and properties file to creates a Streaming app.

How to Build

  • In the main directory, run the following command to install npm packages
    npm install
    
  • Go to embedded-player and install the npm packages
    cd embedded-player
    npm install
    
  • Switch back to main directory and run the redeploy.sh. It compiles and copies the js files to the src/main/webapp/js
    ./redeploy.sh
    

版本与发布记录

@antmedia/webrtc_adaptor 共发布 220 个版本,首次发布于 2022/02/24;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.16.2latest2025/12/0810 个月前
2.16.12025/12/0411 个月前
3.0.0-SNAPSHOT-2025-Nov-09-10-23SNAPSHOT2025/11/0911 个月前
2.16.02025/11/061 年前
3.0.0-SNAPSHOT-2025-Sep-11-05-482025/09/111.2 年前
3.0.0-SNAPSHOT-2025-Aug-31-12-362025/08/311.2 年前

其他发布通道:ALPHA → 2.12.0-ALPHA-2024-Dec-03,SNAPSHOT → 3.0.0-SNAPSHOT-2025-Nov-09-10-23。

关于 @antmedia/webrtc_adaptor 的常见问题

@antmedia/webrtc_adaptor 是什么?

WebRTC Adaptor for implementing a front end using 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 和提交记录判断。