@fishjam-cloud/ts-client

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

Typescript client library for Fishjam

原始使用文档
文档目录6 节
  1. Documentation
  2. Installation
  3. Usage
  4. Examples
  5. License
  6. Fishjam is created by Software Mansion

NPM Version TypeScript Strict TypeDoc

Fishjam TS Client

TypeScript client library for Fishjam.

[!WARNING]
This SDK is not stable yet. We recommend to use React Client for Fishjam services.

Documentation

Documentation is available here or you can generate it locally:

yarn run docs

Installation

You can install this package using npm:

npm install @fishjam-cloud/ts-client

or yarn:

yarn @fishjam-cloud/ts-client

Usage

Prerequisites:

  • Account on Fishjam with App configured.
  • Created room and token of peer in that room. You can use Room Manager to create room and peer token.

The following code snippet is based on the minimal example.

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' }));
}

Examples

For more examples, see the examples folder.

License

Licensed under the Apache License, Version 2.0

Fishjam is created by Software Mansion

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.

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 是什么?

Typescript client library for 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 和提交记录判断。