Index of every page on this site: llms.txt
All skills
Run it yourself

Node.js / TypeScript server SDK for Fishjam — backends that create rooms, mint peer tokens, listen to server notifications, and run agents. Use when writing a Node.js / Express / Fastify / Hono / NestJS backend that talks to Fishjam, sets up a webhook receiver, runs an AI agent, generates livestream tokens, or composes streams. Trigger on: '@fishjam-cloud/js-server-sdk', 'FishjamClient', 'FishjamWSNotifier', 'FishjamAgent', 'createPeer', 'createRoom', 'createAgent', 'createVapiAgent', 'createLivestreamStreamerToken', 'createLivestreamViewerToken', 'refreshPeerToken', 'subscribeTracks', 'subscribePeer', 'createMoqToken', 'ServerMessage', 'roomCreated', 'peerAdded', 'trackAdded', 'fishjam backend Node', 'express fishjam', 'fastify fishjam', 'gemini agent fishjam', 'vapi fishjam', 'CompositionClient', 'createComposition', 'forwardRoomTracks'. Covers REST, WebSocket notifier, webhook protobuf decoding, FishjamAgent, Gemini Live integration, and CompositionClient.

  • 10 files
  • 59.5 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/software-mansion-labs/skills/js-server-sdk

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

composition.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

CompositionClient

Client for Fishjam compositions. Source: packages/js-server-sdk/src/composition.ts in the js-server-sdk repo (https://github.com/fishjam-cloud/js-server-sdk).

Concepts, scenes, templates, and room composition are covered in ../composition/SKILL.md. This file is the TypeScript surface only.

Constructor

import { CompositionClient } from '@fishjam-cloud/js-server-sdk';

const compositionClient = new CompositionClient({
  managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN!,
});
  • Same package and same management token as FishjamClient; no Fishjam ID.
  • Create one per process and share it.

IDs

CompositionId, InputId, OutputId, and RendererId are branded strings. createComposition returns a CompositionId; IDs you choose yourself are cast once:

import type { InputId, OutputId, RendererId } from '@fishjam-cloud/js-server-sdk';

const camera = 'camera' as InputId;
const main = 'main' as OutputId;
const logo = 'logo' as RendererId;

Inside scenes, inputId and imageId are plain strings.

Compositions

const { compositionId } = await compositionClient.createComposition({ autostart: false, cleanupWithoutInputs: false });
const url: string = compositionClient.compositionUrl(compositionId);

await compositionClient.startComposition(compositionId);
await compositionClient.deleteComposition(compositionId);

compositionUrl is synchronous and makes no request; pass its result to fishjamClient.forwardRoomTracks.

Inputs

const { url, bearerToken } = await compositionClient.registerWhipInput(compositionId, camera);
await compositionClient.registerWhipInput(compositionId, camera, { bearerToken: 'chosen-token', video: false });

const publishUrl: string = await compositionClient.registerRtmpInput(compositionId, encoder, { streamKey });

await compositionClient.registerWhepInput(compositionId, remote, { endpointUrl: whepUrl, bearerToken: viewerToken });

const { videoDurationMs, audioDurationMs } = await compositionClient.registerMp4Input(compositionId, intro, {
  url: 'https://smelter.dev/videos/template-scene-race.mp4',
  loop: true,
});

await compositionClient.unregisterInput(compositionId, camera);
await compositionClient.unregisterInput(compositionId, camera, { scheduleTimeMs: 10_000 });
  • registerWhipInput returns the full publish URL, ready to hand to a publisher.
  • registerInput(compositionId, inputId, { type, ... }) is the generic form behind these helpers.

Outputs

await compositionClient.registerWhipOutput(compositionId, main, {
  endpointUrl: fishjamClient.livestreamWhipUrl(),
  bearerToken: streamerToken,
  video: { resolution: { width: 1280, height: 720 }, initial: videoScene },
  audio: { initial: audioScene },
});

await compositionClient.registerRtmpOutput(compositionId, restream, {
  url: ingestUrlWithStreamKey,
  video: { resolution: { width: 1920, height: 1080 }, initial: videoScene },
  audio: { initial: audioScene },
});

await compositionClient.registerTemplateOutput(
  compositionId,
  'show' as OutputId,
  {
    type: 'whip_client',
    endpointUrl: fishjamClient.livestreamWhipUrl(),
    bearerToken: showStreamerToken,
    video: { resolution: { width: 1280, height: 720 }, initial: { root: { type: 'view' } } },
    audio: { initial: { inputs: [] } },
  },
  './my-template/dist/App.js',
);

await compositionClient.updateOutput(compositionId, main, { video: videoScene, audio: audioScene });
await compositionClient.requestKeyframe(compositionId, main);
await compositionClient.unregisterOutput(compositionId, main);
  • Each output pushes to its own destination, so show uses a streamer token of a second livestream room. updateOutput applies to static outputs like main, never to a template output.
  • registerOutput(compositionId, outputId, { type, ... }) is the generic form behind registerWhipOutput and registerRtmpOutput.

Template outputs

registerTemplateOutput(compositionId, outputId, config, template) registers an output and uploads the React template that renders it, in one call. Building the template: ../composition/templates.md.

  • config is the same object registerOutput takes, with type set explicitly ('whip_client' or 'rtmp_client').
  • template is the built bundle (dist/App.js), as a file path or a Blob. A path is read from disk and uploaded, so never pass one taken from user input.
  • video.initial and audio.initial are placeholders. The template replaces both scenes on its first render; pass { root: { type: 'view' } } and { inputs: [] }.
  • Pass audio if the output should be heard. Without it the output has no audio track, whatever the template renders.
  • Change it with sendEvent, never updateOutput: the template owns the scene and its next render replaces your update.
  • Redeploy a new bundle with unregisterOutput, then registerTemplateOutput again. Inputs stay registered; resend the events that carry the template's state.

Assets and events

await compositionClient.registerImage(compositionId, logo, { assetType: 'auto', url: 'https://fishjam.swmansion.com/docs/img/logo.svg' });
await compositionClient.unregisterImage(compositionId, logo);

await compositionClient.registerFont(compositionId, './fonts/Inter.ttf');

await compositionClient.sendEvent(compositionId, { eventName: 'SET_CAPTION', data: { text: 'Welcome!' } });

registerFont takes a file path or a Blob, like registerTemplateOutput.

Related FishjamClient methods

Method Use
forwardRoomTracks(roomId, compositionUrl) Forward a room into a composition (../composition/room-composition.md).
livestreamWhipUrl() endpointUrl for a WHIP output into a Fishjam livestream room.
createLivestreamStreamerToken(roomId) bearerToken for that output (livestream-and-moq.md).
createLivestreamViewerToken(roomId) bearerToken for a WHEP input pulling a private Fishjam livestream.

Types

Scene and config types are exported as types only: VideoScene, AudioScene, Component, View, Tiles, Rescaler, InputStream, Text, Image, Transition, RegisterOutput, WhipOutput, RtmpOutput, ImageSpec, CreateCompositionRequest, UpdateOutputRequest, and more. Write enum-like fields as string literals (type: 'rescaler', mode: 'fill').

import type { AudioScene, VideoScene } from '@fishjam-cloud/js-server-sdk';

Exception types

Composition calls throw the same FishjamBaseException hierarchy as FishjamClient (client.md), plus not-found types for composition resources:

Exception When
CompositionNotFoundException The composition does not exist, for example after idle cleanup or deletion.
InputNotFoundException, OutputNotFoundException, RendererNotFoundException The input, output, or image does not exist.
BadRequestException Invalid body, such as a mismatched updateOutput or an odd resolution. details carries the server message.
UnauthorizedException Wrong management token.
ServiceUnavailableException Temporarily unavailable; retry with backoff.

Sources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 43cde80. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month

README badge

README badge for software-mansion-labs/skills/js-server-sdk