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.

express-fastify.md

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

Express / Fastify Wiring

Production-quality patterns for hosting Fishjam from a Node.js backend. Covers both Express (most common) and Fastify (the example pattern in the official docs).

Single client per process

Always — one FishjamClient shared across all routes / requests. It's an axios wrapper, not a connection pool. Re-instantiating per request leaks.

const fishjamClient = new FishjamClient({
  fishjamId: process.env.FISHJAM_ID!,
  managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN!,
});

Express — the canonical /api/join-room endpoint

import express from 'express';
import {
  FishjamClient,
  FishjamBaseException,
  FishjamNotFoundException,
  UnauthorizedException,
  BadRequestException,
  ServiceUnavailableException,
} from '@fishjam-cloud/js-server-sdk';

const app = express();
app.use(express.json());

const fishjamClient = new FishjamClient({
  fishjamId: process.env.FISHJAM_ID!,
  managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN!,
});

// Map Fishjam exceptions to HTTP responses. Called explicitly from each route's catch
function respondFishjamError(err: unknown, res: express.Response) {
  if (err instanceof FishjamNotFoundException) {
    return res.status(404).json({ error: err.message });
  }
  if (err instanceof BadRequestException) {
    return res.status(400).json({ error: err.message, details: err.details });
  }
  if (err instanceof UnauthorizedException) {
    // Our credentials are bad — surface this as a server error, NOT a user 401.
    console.error('Fishjam auth failure — check FISHJAM_MANAGEMENT_TOKEN', err);
    return res.status(502).json({ error: 'Upstream auth failure' });
  }
  if (err instanceof ServiceUnavailableException) {
    return res.status(503).json({ error: 'Upstream unavailable' });
  }
  if (err instanceof FishjamBaseException) {
    // Catch-all for any other Fishjam exception (incl. 403 surfaced as UnknownException).
    return res.status(502).json({ error: 'Upstream error', status: err.statusCode, details: err.details });
  }
  console.error('Unhandled error', err);
  return res.status(500).json({ error: 'Internal server error' });
}

// Your own auth middleware. NOT Fishjam's — it verifies YOUR user.
app.use(authenticateUser);

app.post('/api/join-room', async (req, res) => {
  try {
    const { roomName, roomType = 'conference' } = req.body;
    const user = req.user;

    if (!userCanJoin(user, roomName)) {
      return res.status(403).json({ error: 'Forbidden' });
    }

    // Either look up an existing room by name in your DB, or create a fresh one.
    const room = await getOrCreateRoom(roomName, roomType);

    const { peer, peerToken } = await fishjamClient.createPeer(room.id, {
      metadata: { userId: user.id, name: user.name, role: user.role },
    });

    res.json({ peerToken, roomId: room.id, fishjamId: process.env.FISHJAM_ID });
  } catch (err) {
    respondFishjamError(err, res);
  }
});

app.listen(3000);

If the app already centralizes errors in a four-argument Express error-handling middleware, next(err) from the catch block reaches it the same way (that's the pattern Express's own error-handling guide documents) — but don't introduce one just for Fishjam; the explicit helper is simpler and framework-portable.

Fishjam-specific decisions for this endpoint:

  • Idempotency — pick whether roomName resolves to an existing room or always creates a new one. Match your product's semantics.
  • Authorization — userCanJoin(user, roomName) is the policy hook. Fishjam authorizes the token bearer, not your user. Enforce your rules here.

Fastify — official pattern

The Fastify docs show the SDK wired as a plugin so fastify.fishjam is decorated everywhere:

import fastifyPlugin from 'fastify-plugin';
import { FishjamClient } from '@fishjam-cloud/js-server-sdk';

declare module 'fastify' {
  interface FastifyInstance {
    fishjam: FishjamClient;
    config: { FISHJAM_ID: string; FISHJAM_MANAGEMENT_TOKEN: string };
  }
}

export const fishjamPlugin = fastifyPlugin((fastify) => {
  fastify.decorate(
    'fishjam',
    new FishjamClient({
      fishjamId: fastify.config.FISHJAM_ID,
      managementToken: fastify.config.FISHJAM_MANAGEMENT_TOKEN,
    }),
  );
});

Routes:

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

fastify.post<{ Body: { roomName: string; roomType?: RoomType } }>(
  '/api/join-room',
  async (request, reply) => {
    const { roomName, roomType = 'conference' } = request.body;
    const room = await getOrCreateRoom(roomName, roomType);
    const { peer, peerToken } = await fastify.fishjam.createPeer(room.id, {
      metadata: { userId: request.user.id },
    });
    return { peerToken, roomId: room.id };
  },
);

fastify.get('/api/rooms', () => fastify.fishjam.getAllRooms());

For Fastify notifier and webhook wiring, see ws-notifier.md and webhooks.md, plus the official guide at https://fishjam.swmansion.com/docs/how-to/backend/fastify-example.

Combining /api/join-room + webhook + notifier

Common production shape:

Concern Where it lives
/api/join-room (mint peer token) HTTP route — see Express / Fastify above
/api/leave-room (optional explicit cleanup) HTTP route → fishjamClient.deletePeer(roomId, peerId)
/api/admin/rooms (debugging) HTTP route → fishjamClient.getAllRooms()
/webhooks/fishjam/:secret (events) Raw-body route, ServerMessage.decode; see webhooks.md
FishjamWSNotifier (events, alt) Background plugin / startup hook; see ws-notifier.md
Token refresh (long-lived peers) Cron / scheduler calling fishjamClient.refreshPeerToken(...); ship new token via websocket / SSE to the client

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