Skip to main content
Version: 0.20.0

Private vs Public Livestreams

info

This explanation only applies to Fishjam rooms with type livestream.

When livestreaming with Fishjam, you can chose to make your livestream private or public. By default, created livestreams are private, to prevent possible bugs.

import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; const fishjamClient = new FishjamClient({ fishjamId, managementToken, }); const privateRoom = await fishjamClient.createRoom({ roomType: 'livestream' }); const publicRoom = await fishjamClient.createRoom({ roomType: 'livestream', public: true });

The choice you make affects how viewers connect to the livestream and has no effect on streamers.

Private livestreams

When you create a private livestream, viewers are required to provide a viewer token when connecting to the livestream.

This aims to provide control over who can view a livestream, but requires you to distribute tokens from your backend application to your frontend applications.

Creating a viewer token

Below we show how you would create a livestream viewer token in a production scenario, with your own backend. Note that for development purposes, you can use the Sandbox API to generate a viewer token.

import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; const fishjamClient = new FishjamClient({ fishjamId, managementToken, }); const privateRoom = await fishjamClient.createRoom({ roomType: 'livestream' }); const { token: viewerToken } = await fishjamClient.createLivestreamViewerToken(privateRoom.id);

Connecting to a private room

Once you've created a viewer token, you can connect to a room using the Fishjam client SDKs (examples below), or alternatively you can use WHEP.

import { useLivestreamViewer } from '@fishjam-cloud/react-client'; // ... const { connect, stream } = useLivestreamViewer(); // ... await connect({ token: viewerToken }); // after connecting stream will be available

Public livestreams

Public livestreams simplify the viewing process by omitting the viewer token. All a viewer needs to view a public livestream is the ID of the room, so your backend doesn't need to manage the creation and distribution of viewer tokens.

Note however, that public livestreams are not suitable for all use-cases.

For example, if you are developing an app, which includes exclusive live content that requires a subscription to view, then you will want to authorize viewers before allowing them to view a livestream. Failing to do so may result in extra costs, as livestreams are billed per-viewer. Such an application will benefit from the token-based authorization in private livestreams.

Connecting to a public room

Once you've created a room of type livestream with the public flag enabled, you may start connecting viewers to the stream via the Fishjam client SDKs or WHEP.

import { useLivestreamViewer } from '@fishjam-cloud/react-client'; // ... const { connect, stream } = useLivestreamViewer(); // ... await connect({ streamId: roomId }); // after connecting `stream` will be available