Web Publishing
This tutorial explains how to publish a live stream from the browser using Media over QUIC (MoQ) with Fishjam. To watch a stream instead, see Web Subscribing.
If you're new to MoQ, then we recommend getting familiar with the MoQ with Fishjam explanation.
To start publishing a MoQ stream, you need a publisher connection URL — the relay URL with a publisher token embedded as a ?jwt= query parameter. We show how to quickly prototype with the Sandbox API and how to get ready for production.
MoQ is a protocol with a well-defined negotiation, so in theory any compliant MoQ client should work. That said, we recommend using the @moq client libraries — the reference TypeScript implementation maintained alongside the protocol. For more details, see the documentation.
Quickstart with the Sandbox API
If you don't have a backend server set up, you can prototype publishing using the Sandbox API.
Obtaining a publisher connection URL
For more on what the Sandbox API is and its limitations, see What is the Sandbox API?.
To obtain a MoQ connection URL you'll need your Sandbox API URL. If you don't have it already, see Sandbox API URL.
- React
- TS
If you're using React, the useSandbox hook from @fishjam-cloud/react-client wraps the Sandbox API request for you:
import {useSandbox } from "@fishjam-cloud/react-client"; constPUBLISHER_PATH = "stream-alice"; constSANDBOX_API_URL = "YOUR_SANDBOX_API_URL"; // Inside a React component: const {getSandboxMoqPublisherAccess } =useSandbox ({sandboxApiUrl :SANDBOX_API_URL , }); // Request a publisher connection URL scoped to the publisher path const {connection_url :publishUrl } = awaitgetSandboxMoqPublisherAccess (PUBLISHER_PATH );
If you don't want to use React or pull in the whole client library just for the useSandbox hook, you can call the Sandbox API directly with fetch:
constPUBLISHER_PATH = "stream-alice"; constSANDBOX_API_URL = "YOUR_SANDBOX_API_URL"; constresponse = awaitfetch ( `${SANDBOX_API_URL }/moq/${PUBLISHER_PATH }/publisher`, ); const {connection_url :publishUrl } = awaitresponse .json ();
Connecting and publishing
Install the MoQ packages:
- npm
- Yarn
- pnpm
- Bun
npm install @moq/lite @moq/publish
yarn add @moq/lite @moq/publish
pnpm add @moq/lite @moq/publish
bun add @moq/lite @moq/publish
Use the connection URL to connect to the Fishjam MoQ relay and start broadcasting:
// Connect to the Fishjam MoQ relay using the publisher connection URL constconnection = awaitMoq .Connection .connect (newURL (publishUrl )); constcamera = newPublish .Source .Camera ({enabled : true }); constmicrophone = newPublish .Source .Microphone ({enabled : true }); // Set up a broadcast with video and audio tracks constbroadcast = newPublish .Broadcast ({connection ,name :Moq .Path .from (PUBLISHER_PATH ),enabled : true,video : {source :camera .source ,hd : {enabled : true }, },audio : {enabled : true,source :microphone .source , }, });
The stream is now live on the MoQ relay! Viewers can now start watching it — follow Web Subscribing.
Production with Server SDKs
The Quickstart gets you publishing quickly. In production, your backend generates tokens with proper authorization, so you control who can publish.
A publisher connection URL grants write access to a specific path. Generate one on your backend and deliver it to the broadcasting client:
- TypeScript
- Python
import {FishjamClient } from '@fishjam-cloud/js-server-sdk'; constfishjamClient = newFishjamClient ({fishjamId ,managementToken , }); conststreamPath = 'stream-alice'; // Generate a connection URL that allows publishing to 'stream-alice' const {connection_url :publishUrl } = awaitfishjamClient .createMoqAccess ({publishPath :streamPath , });
from fishjam import FishjamClient fishjam_client = FishjamClient( fishjam_id=fishjam_id, management_token=management_token, ) stream_path = 'stream-alice' # Generate a connection URL that allows publishing to 'stream-alice' publish_url = fishjam_client.create_moq_access(publish_path=stream_path).connection_url
Deliver this connection URL to the broadcasting client, then use it to connect as described in Connecting and publishing.
See also
- Web Subscribing — watch a MoQ stream in the browser
- MoQ with Fishjam — how MoQ works in Fishjam
- Livestreaming — the WebRTC (WHIP/WHEP) approach
- WHIP/WHEP with Fishjam