@dyteinternals/mediasoup-client

中文文档
3.6.89发布于 2023/12/12ISCTypeScriptCommonJS近 30 天下载 4178

mediasoup client side JavaScript library

原始使用文档
文档目录7 节
  1. Website and Documentation
  2. Support Forum
  3. Usage Example
  4. Authors
  5. Social
  6. Sponsor
  7. License

mediasoup-client v3

JavaScript client side library for building mediasoup based applications.

Website and Documentation

Support Forum

Usage Example

import { Device } from 'mediasoup-client';
import mySignaling from './my-signaling'; // Our own signaling stuff.

// Create a device (use browser auto-detection).
const device = new Device();

// Communicate with our server app to retrieve router RTP capabilities.
const routerRtpCapabilities = await mySignaling.request('getRouterCapabilities');

// Load the device with the router RTP capabilities.
await device.load({ routerRtpCapabilities });

// Check whether we can produce video to the router.
if (!device.canProduce('video'))
{
  console.warn('cannot produce video');

  // Abort next steps.
}

// Create a transport in the server for sending our media through it.
const { 
  id, 
  iceParameters, 
  iceCandidates, 
  dtlsParameters,
  sctpParameters
} = await mySignaling.request(
  'createTransport',
  {
    sctpCapabilities : device.sctpCapabilities
  });

// Create the local representation of our server-side transport.
const sendTransport = device.createSendTransport(
  {
    id, 
    iceParameters, 
    iceCandidates, 
    dtlsParameters,
    sctpParameters
  });

// Set transport "connect" event handler.
sendTransport.on('connect', async ({ dtlsParameters }, callback, errback) =>
{
  // Here we must communicate our local parameters to our remote transport.
  try
  {
    await mySignaling.request(
      'transport-connect',
      {
        transportId: sendTransport.id,
        dtlsParameters
      });

    // Done in the server, tell our transport.
    callback();
  }
  catch (error)
  {
    // Something was wrong in server side.
    errback(error);
  }
});

// Set transport "produce" event handler.
sendTransport.on(
  'produce',
  async ({ kind, rtpParameters, appData }, callback, errback) =>
  {
    // Here we must communicate our local parameters to our remote transport.
    try
    {
      const { id } = await mySignaling.request(
        'produce',
        { 
          transportId : sendTransport.id,
          kind,
          rtpParameters,
          appData
        });

      // Done in the server, pass the response to our transport.
      callback({ id });
    }
    catch (error)
    {
      // Something was wrong in server side.
      errback(error);
    }
  });

// Set transport "producedata" event handler.
sendTransport.on(
  'producedata',
  async ({ sctpStreamParameters, label, protocol, appData }, callback, errback) =>
  {
    // Here we must communicate our local parameters to our remote transport.
    try
    {
      const { id } = await mySignaling.request(
        'produceData',
        { 
          transportId : sendTransport.id,
          sctpStreamParameters,
          label,
          protocol,
          appData
        });

      // Done in the server, pass the response to our transport.
      callback({ id });
    }
    catch (error)
    {
      // Something was wrong in server side.
      errback(error);
    }
  });

// Produce our webcam video.
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const webcamTrack = stream.getVideoTracks()[0];
const webcamProducer = await sendTransport.produce({ track: webcamTrack });

// Produce data (DataChannel).
const dataProducer =
  await sendTransport.produceData({ ordered: true, label: 'foo' });

Authors

Social

Sponsor

You can support mediasoup by sponsoring it. Thanks!

License

ISC

版本与发布记录

@dyteinternals/mediasoup-client 共发布 14 个版本,首次发布于 2023/02/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.6.89latest2023/12/122 年前
3.6.882023/11/272 年前
3.6.872023/11/242 年前
3.6.86-test2023/10/253 年前
3.6.862023/10/243 年前
3.6.852023/10/043 年前

其他发布通道:tl → 3.6.82-t.1。

关于 @dyteinternals/mediasoup-client 的常见问题

@dyteinternals/mediasoup-client 是什么?

mediasoup client side JavaScript library

如何安装 @dyteinternals/mediasoup-client?

在项目目录运行 npm install @dyteinternals/mediasoup-client,或使用 pnpm add / yarn add / bun add。

@dyteinternals/mediasoup-client 支持 TypeScript 吗?

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

@dyteinternals/mediasoup-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dyteinternals/mediasoup-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dyteinternals/mediasoup-client 可以商用吗?

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

@dyteinternals/mediasoup-client 的下载量有多少?

根据 npm 官方下载统计,@dyteinternals/mediasoup-client 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,178 次,日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dyteinternals/mediasoup-client 还在维护吗?

最新版本 3.6.89 发布于 2023/12/12(2 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。