@fishjam-cloud/ts-client

中文文档
0.31.1发布于 2026/10/22Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.9万

Fishjam 的打字客户端库

中文使用文档
文档目录6 节
  1. 文档
  2. 安装
  3. 使用量
  4. 实例
  5. 许可证
  6. Fishjam由软件人大厦创建

NPM Version TypeScript Strict TypeDoc

Fishjam TS 客户端

类型脚本客户端库 鱼潭。 。 。 .

[尖叫声]
这个SDK还不稳定 我们建议使用 反应客户端 服务费.

文档

备有文件 这里 或者说 您可以在本地生成 :

yarn run docs

安装

您可以使用 npm数字 :

npm install @fishjam-cloud/ts-client

或者说 yarn数字 :

yarn @fishjam-cloud/ts-client

使用量

先决条件:

  • 账户 鱼潭 已配置 App .
  • 在那间屋子里创建了房间和同伴的标志 您可以使用 Room Management 来创建房间和对等标志 .

以下代码片断基于 最小 实例.

import { FishjamClient, WebRTCEndpoint } from '@fishjam-cloud/ts-client';

const SCREEN_SHARING_MEDIA_CONSTRAINTS = {
  video: {
    frameRate: { ideal: 20, max: 25 },
    width: { max: 1920, ideal: 1920 },
    height: { max: 1080, ideal: 1080 },
  },
};

// Example metadata types for peer and track
// You can define your own metadata types, just make sure they are serializable
type PeerMetadata = {
  name: string;
};

type TrackMetadata = {
  type: 'camera' | 'screen';
};

// Create a new FishjamClient object to interact with Fishjam
const client = new FishjamClient<PeerMetadata, TrackMetadata>();

const peerToken = prompt('Enter peer token') ?? 'YOUR_PEER_TOKEN';

const FISHJAM_URL = 'ws://localhost:5002';

// Start the peer connection
client.connect({
  peerMetadata: { name: 'peer' },
  token: peerToken,
  url: FISHJAM_URL,
});

// You can listen to events emitted by the client
client.on('joined', (peerId, peersInRoom) => {
  // Check if webrtc is initialized
  if (!client.webrtc) return console.error('webrtc is not initialized');

  // To start broadcasting your media, you will need a source of MediaStream like a camera, microphone, or screen
  // In this example, we will use screen sharing
  startScreenSharing(client.webrtc);
});

// To receive media from other peers, you need to listen to the onTrackReady event
client.on('trackReady', (ctx) => {
  const peerId = ctx.peer.id;

  document.getElementById(peerId)?.remove(); // remove previous video element if it exists

  // Create a new video element to display the media
  const videoPlayer = document.createElement('video');
  videoPlayer.id = peerId;
  videoPlayer.oncanplaythrough = function () {
    // Chrome blocks autoplay of unmuted video
    videoPlayer.muted = true;
    videoPlayer.play();
  };
  document.body.appendChild(videoPlayer);

  videoPlayer.srcObject = ctx.stream; // assign MediaStream to video element
});

// Cleanup video element when track is removed
client.on('trackRemoved', (ctx) => {
  const peerId = ctx.peer.id;
  document.getElementById(peerId)?.remove(); // remove video element
});

async function startScreenSharing(webrtc: WebRTCEndpoint) {
  // Get screen sharing MediaStream
  const screenStream = await navigator.mediaDevices.getDisplayMedia(SCREEN_SHARING_MEDIA_CONSTRAINTS);

  // Add local MediaStream to webrtc
  screenStream.getTracks().forEach((track) => webrtc.addTrack(track, { type: 'screen' }));
}

实例

更多例子,见 实例 文件夹.

许可证

凭 Apache 许可证,2.0版本

Fishjam由软件人大厦创建

2012年以来 软件大楼 是一个在网络和移动方面有经验的软件机构 应用程序。 我们是核心反动土著贡献者和处理各种反动土著问题的专家。 我们可以帮忙 你造下一个梦想产品 雇我们。 。 。 .

Software Mansion

版本与发布记录

@fishjam-cloud/ts-client 共发布 58 个版本,首次发布于 2024/08/02;过去 12 个月发布了 31 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.31.1latest2026/10/2223 天前
0.31.02026/09/301 个月前
0.30.22026/09/191 个月前
0.30.2-rc.0rc2026/09/142 个月前
0.30.12026/09/102 个月前
0.30.02026/08/262 个月前

关于 @fishjam-cloud/ts-client 的常见问题

@fishjam-cloud/ts-client 是什么?

Fishjam 的打字客户端库

如何安装 @fishjam-cloud/ts-client?

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

@fishjam-cloud/ts-client 支持 TypeScript 吗?

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

@fishjam-cloud/ts-client 支持 ESM 还是 CommonJS?

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

@fishjam-cloud/ts-client 可以商用吗?

@fishjam-cloud/ts-client 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@fishjam-cloud/ts-client 的下载量有多少?

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

@fishjam-cloud/ts-client 还在维护吗?

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