Testing with the Sandbox API
The Sandbox API is a development tool that lets you create rooms and peers for testing without setting up your own backend server. This guide shows you how to use it effectively.
Prerequisites
- Access to Fishjam Dashboard
Step 1: Get your Fishjam ID and Sandbox API URL
- Log in to Fishjam Dashboard
- Navigate to the Sandbox tab
- Copy your Fishjam ID
- In the Sandbox API section, copy your Sandbox API URL
You need both values for React/React Native apps:
Sandbox API urlis used to call the Sandbox API to create test rooms and return peer tokens.Fishjam IDis passed toFishjamProviderso the client can connect to the Fishjam media server after it gets a peer token.
Step 2: Create a room and get peer tokens
With the useSandbox hook
- React Native
- React
import {useSandbox } from '@fishjam-cloud/react-native-client'; // ... constSANDBOX_API_URL = "your-sandbox-api-url-here"; const {getSandboxPeerToken } =useSandbox ({sandboxApiUrl :SANDBOX_API_URL }); constpeerToken = awaitgetSandboxPeerToken (roomName ,peerName );
import {useSandbox } from '@fishjam-cloud/react-client'; // ... constSANDBOX_API_URL = "your-sandbox-api-url-here"; const {getSandboxPeerToken } =useSandbox ({sandboxApiUrl :SANDBOX_API_URL }); constpeerToken = awaitgetSandboxPeerToken (roomName ,peerName );
Required parameters
roomName- Name of the room to create/joinpeerName- Name for the peer joining the room
Optional parameters
roomType- Type of room to create (defaults toconference)
Room types available
conference- For video/audio conferencing (default)audio_only- For audio-only conferencinglivestream- For one-to-many video/audio streaming
Step 3: Handle the response
The Sandbox API returns a JSON response with connection details:
{ "peerToken": "<PEER_TOKEN>", "room": { "id": "<ROOM_ID>", "name": "foo" }, "peer": { "id": "<PEER_ID>", "name": "bar" } }
Step 4: Use the tokens in your client app
Below are examples on how to use tokens from the Sandbox API in your frontend applications:
- React Native
- React
import {useSandbox } from "@fishjam-cloud/react-native-client"; export default functionTestScreen () { const [peerToken ,setPeerToken ] =useState <string | null>(null); // fishjamId is provided through FishjamProvider const {getSandboxPeerToken } =useSandbox ({sandboxApiUrl :SANDBOX_API_URL });useEffect (() => { constfetchPeerToken = async () => { try { consttoken = awaitgetSandboxPeerToken (roomName ,peerName );setPeerToken (token ); } catch (error ) {console .error ("Failed to create room:",error ); } };fetchPeerToken (); }, []); if (!peerToken ) { return <Text >Creating room...</Text >; } return ( <RoomView peerToken ={peerToken } /> ); }
import {FishjamProvider ,useConnection ,useSandbox } from "@fishjam-cloud/react-client"; functionVideoCallComponent () { const {joinRoom ,peerStatus } =useConnection (); const {getSandboxPeerToken } =useSandbox ({sandboxApiUrl :SANDBOX_API_URL }); consthandleJoinRoom = async () => { constroomName = "testRoom"; constpeerName = `user_${Date .now ()}`; try { constpeerToken = awaitgetSandboxPeerToken (roomName ,peerName ) awaitjoinRoom ({peerToken }); } catch (error ) {console .error ("Failed to join room:",error ); } }; constisConnected =peerStatus === "connected"; return ( <div > {isConnected ? <p >Connected to room!</p > : <button onClick ={handleJoinRoom }>Join Room</button >} </div > ); } export default functionApp () { return ( <FishjamProvider fishjamId ={FISHJAM_ID }> <VideoCallComponent /> </FishjamProvider > ); }
Step 5: Test different room types
Testing audio-only rooms
constaudioOnlyPeerToken = awaitgetSandboxPeerToken ( "audioTest", "user1", "audio_only", );
Testing livestream rooms
constlivestreamName = "livestream1"; // For the streamer conststreamerData = awaitgetSandboxLivestream (livestreamName ); // For viewers, you need a viewer token (different endpoint) constviewerToken = awaitgetSandboxViewerToken (livestreamName );
Step 6: Handle multiple peers
To test with multiple participants, create multiple peer tokens with different peer names:
// First peer constpeer1Response = awaitgetSandboxPeerToken ("multiTest", "alice"); // Second peer constpeer2Response = awaitgetSandboxPeerToken ("multiTest", "bob");
Both peers will join the same room (multiTest) and can communicate with each other.
Common testing patterns
Pattern 1: Random room names for isolation
constroomName = `test_${Math .random ().toString (36).substring (7)}`; constpeerName = `user_${Date .now ()}`;
Pattern 2: Consistent naming for repeated tests
constroomName = "development-room"; constpeerName = `developer_1`;
Pattern 3: Feature-specific room names
constroomName = `screenshare-test-${Date .now ()}`; constroomName = `audio-only-test`; constroomName = `livestream-demo`;
Troubleshooting
Issue: Room not found errors
Problem: Rooms might not persist between requests.
Solution: Always create rooms fresh for each test session.
Issue: Connection failures
Problem: Invalid Fishjam ID, invalid Sandbox API URL, disabled Sandbox API, or network issues.
Solution:
- Verify your Fishjam ID in the Fishjam Dashboard.
- Verify your Sandbox API URL in the Sandbox tab.
- Make sure the Sandbox API is enabled.
- Check network connectivity.
Security reminder
The Sandbox API is not safe for production!
- No authentication required
- Anyone with your Sandbox API URL can create rooms and peer tokens
- Identical room/peer names get the same tokens
- No rate limiting or abuse protection
Only use the Sandbox API for development and testing.
Managing your Sandbox API
Manage the Sandbox API from the Sandbox tab:
- If your Sandbox API URL is exposed or credentials are compromised, click Generate new URL. This invalidates the old URL.
- If you want to stop using it, click Disable Sandbox API.
- When you want to use it again, click Enable Sandbox API.
Your
FISHJAM_IDis still required byFishjamProviderto connect to the Fishjam media server. The Sandbox API URL is only used to request test room and peer tokens.
Next steps
Once you've tested your integration with the Sandbox API:
For production deployment: