@flussonic/flussonic-webrtc-player

中文文档
24.7.1-10-g016867a发布于 2026/03/31ISCCommonJS近 30 天下载 2338

Flussonic Webrtc publish and playback

原始使用文档
文档目录11 节
  1. Installation
  2. Development
  3. Publisher
  4. Usage
  5. Fields
  6. Methods
  7. Example
  8. Player
  9. Usage
  10. Methods
  11. Example

flussonic-webrtc-player

Flussonic WebRTC Player is a JavaScript library for publishing and playing video via WebRTC. It relies on Flussonic backend, HTML5 video and WebRTC.

Install it in your project and use in your website or application to exchange video via WebRTC with Flussonic.

The library contains classes:

  • Publisher for video publication from your app to Flussonic Media Server.
  • Player for playback of published video in your app.

Installation

Install flussonic-webrtc-player from NPM by running the command:

npm install --save @flussonic/flussonic-webrtc-player

Development

To run embed version of player in development mode, you must build it first:

yarn build:flussonic

and then run it in dev mode:

yarn start:embed

Publisher

Used to stream video via WebRTC from a client app to other clients through Flussonic.

Usage

With webpack

import {
  Publisher,
  PUBLISHER_EVENTS,
  PUBLISHER_STATUSES,
} from '@flussonic/flussonic-webrtc-player';
// ...
const publisher = new Publisher(url, opts, shouldLog);

With script tag:

<script type="text/javascript" src="../../dist/index.js"></script>
<script>
  const { Publisher, PUBLISHER_EVENTS, PUBLISHER_STATUSES } =
    window.FlussonicWebRTCPlayer;
  // ...
  const publisher = Publisher(url, opts, shouldLog);
</script>

Where:

url - a stream's URL.

opts - a plain object, it can include:

  • preview?: HTMLMediaElement - if passed, then shows preview before the stream is loaded. This is an element in which you can output a published stream without creating a separate player listening to the same stream.

  • previewOptions?: object - preview options object.

  • previewOptions?.autoplay? - if true, the playback of the preview will start automatically.

  • previewOptions?.controls? - if true, the preview will have controls.

  • previewOptions?.muted? - if true, the preview will be muted.

  • inputStreams - now you can send your MediaStreamTracks directly to publisher and publish them

  • constraints - MediaStreamConstraints.

  • shouldLog - if passed, internal events will be logged to console (true|false).

  • returnCapabilities() - callback for getting video device capabilities.

  • password - pass a stream password.

  • authTokenName - set a custom password token name

  • tokenValue - set a token value

  • maxBitrate - sets the maxBitrate iceCandidate option in the publisher.

  • onEvent() - Publisher events callback. For tracking connection states and player workflow. Events are listed below:

    • { type: 'started', started_at: #Date# } - runs when the streaming is started.
    • { type: 'closed', closed_at: #Date# } - runs when the streaming is closed.
    • {type: 'connection state', connection: 'connected' } - runs when connection state changes. States are listed below:
      • opened - when connection is opened
      • connected - when ICE candidates is connected
      • closed - when user performed connection close
      • disconnected - when server side closed ICE candidates connection
  • canvasCallback - callback function than enables both canvas preview and canvas publish. Returns a canvas html element that you can modify in realtime to add some video effects to publishing video stream.

  • radeonCheck - Enable workaround for the issue when some AMD Radeon(tm) publish with a low bitrate. This is experimental option, will be redesigned.

Fields

  • status - the status of a current publisher, possible values are 'initializing'|'streaming'|'stopped'.

Methods

  • start(opts) - starts publication and sets the current publisher's status to streaming.
start(opts?: {
  openPeerConnectionOptions?: {
    getMediaOptions?: {
      // Called if mediaDevices.getUserMedia fails
      onGetUserMediaError: (error: Error) => void
    }
  }
}) => void
  • shareScreen() - allows the user to activate screen casting after publishing has started. To stop screen sharing you got to call this method again.

  • stop() - stops stream's tracks; sets the current publisher status to stopped.

  • restart() - restarts the publishing process.

  • on(event, cb) - subscribes for event with the callback cb. Events are listed below:

    • STREAMING - runs when an ICE candidate is received and the streaming is started.
  • mute() - mutes the published audio track.

  • switchTrack(track) - method to switch RTCRtpTransceiver sender tracks after publishing starts, track is for user's new MediaStreamTrack.

Example

import {
  Publisher,
  PUBLISHER_EVENTS,
  PUBLISHER_STATUSES,
} from '@flussonic/flussonic-webrtc-player';
const publisher = new Publisher(
  // The URL to a Flussonic stream that has a published source
  'https://FLUSSONIC_IP/STREAM_NAME',
  {
    // A <video> or <audio> element for previewing a published stream
    preview: document.getElementById('preview'),
    previewOptions: {
      autoplay: true,
      controls: true,
      muted: false,
    },
    constraints: {
      video: {
        width: { min: 320, ideal: 1920, max: 4096 },
        height: { min: 240, ideal: 1080, max: 2160 },
      },
      audio: true,
    },
  },
  // Log to console the Publisher's internal debug messages?
  true,
);
publisher.on(PUBLISHER_EVENTS.STREAMING, () => {
  console.log('Streaming started');
});
publisher.start();
// ...
publisher.stop();

Player

Used for playing back video from Flussonic via WebRTC on a client.

Usage

With webpack

import { Player, PLAYER_EVENTS } from '@flussonic/flussonic-webrtc-player';
// ...
const player = new Player(element, url, opts, shouldLog);

With script tag:

<script type="text/javascript" src="../../dist/index.js"></script>
<script>
  const { Player, PLAYER_EVENTS } = window.FlussonicWebRTCPlayer;
  // ...
  const player = new Player(element, url, opts, shouldLog);
</script>

Where:

element - a <video> DOM element used for viewing a stream.

url - the stream's URL.

opts - a plain object, it can include options:

  • autoplay - starts playback automatically (true|false).

  • shouldLog - if passed, internal events will be logged to console (true|false).

  • onMediaInfo(tracks, abr) - returns MediaInfo object with tracks information, and ABR(Adaptive Bitrate Streaming) indication flag

  • onTrackInfo(trackInfo) - returns a track info on track change, useful for ABR mode info

  • onEvent() - Player events callback.

  • authTokenName - set a custom password token name

  • tokenValue - set a token value

  • start_track - initiates the playback track (v1a1 | auto).

  • videoDisabled - disables the video transceiver.

  • audioDisabled - disables the audio transceiver.

Methods

  • play() - starts the playback.

  • changeTracks(['v1','a1']) - manualy change tracks. Can be [] or 'auto', if source has ABR. Tracklist and abr flag can be achieved by using onMediaInfo callback.

  • stop() - stops the playback, sets srcObject of <video> to null.

  • destroy() - calls stop() and unbinds all listeners.

  • on(event, cb) - subscribes for event with the callback cb. Events are listed below:

    • FAIL - when an error occurs, runs with the message that describes this error.
    • PLAY - runs when playback starts.
    • DEBUG - for development puproses.
  • getMediaInfo() - retrieves media information about the stream.

Example

import { Player, PLAYER_EVENTS } from '@flussonic/flussonic-webrtc-player';
const player = new Player(
  // A <video> or <audio> element to playback the stream from Flussonic
  document.getElementById('player'),
  // The URL of the stream from Flussonic
  'https://FLUSSONIC_IP/STREAM_NAME',
  // Options
  { autoplay: true },
  // Log to console the Player's internal debug messages?
  true,
);
player.on(PLAYER_EVENTS.PLAY, (msg) => console.log(`Play: ${msg}`));
player.on(PLAYER_EVENTS.DEBUG, (msg) => console.log(`Debug: ${msg}`));
player.play();
player.changeTracks('auto');
// ...
player.stop();
// ...
player.destroy();

版本与发布记录

@flussonic/flussonic-webrtc-player 共发布 147 个版本,首次发布于 2019/02/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
24.7.1-10-g016867alatest2026/03/317 个月前
24.7.1-8-geaef8572025/07/081.4 年前
24.7.1-6-g395cdc72025/03/061.7 年前
24.7.1-2-g1b8eaa22024/07/222 年前
24.7.1-0-g20fa1ce2024/07/112 年前
24.6.1-7-g04ca7102024/07/112 年前

其他发布通道:beta → 23.4.1-beta.0。

关于 @flussonic/flussonic-webrtc-player 的常见问题

@flussonic/flussonic-webrtc-player 是什么?

Flussonic Webrtc publish and playback

如何安装 @flussonic/flussonic-webrtc-player?

在项目目录运行 npm install @flussonic/flussonic-webrtc-player,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@sentry/browser(^5.8.0)、core-js(^2.5.7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flussonic/flussonic-webrtc-player 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/flussonic__flussonic-webrtc-player 是否存在。

@flussonic/flussonic-webrtc-player 支持 ESM 还是 CommonJS?

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

@flussonic/flussonic-webrtc-player 可以商用吗?

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

@flussonic/flussonic-webrtc-player 的下载量有多少?

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

@flussonic/flussonic-webrtc-player 还在维护吗?

最新版本 24.7.1-10-g016867a 发布于 2026/03/31(7 个月前);至今共发布 147 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/02/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。