Skip to main content
Version: Next

Connecting

This article will guide you through the process of connecting to a Fishjam room.

Getting URL and token

In order to connect, you need to obtain a Peer Token (the token that will authenticate the peer in your Room).

Once you create your account on Fishjam, you can use the Sandbox API to generate peer tokens for testing or development purposes without setting up your own backend. This is basically a service that will create a Room, add your app as the Room's Peer, and return the token required to use that Room. It is available to all accounts, including the free Mini Jar plan. For React/React Native apps, copy both the Fishjam ID from the Dashboard tab and Sandbox API URL from the Sandbox tab: the Sandbox API URL is used to get peer tokens, while the Fishjam ID is passed to FishjamProvider for media server access.

const { getSandboxPeerToken } = useSandbox({ sandboxApiUrl: SANDBOX_API_URL }); const peerToken = await getSandboxPeerToken(roomName, peerName);

Connecting

Use the useConnection hook to get the joinRoom function.

import { useConnection, useSandbox } from "@fishjam-cloud/react-client"; import React, { useCallback } from "react"; export function JoinRoomButton() { const { joinRoom } = useConnection(); // get the peer token from sandbox or your backend const { getSandboxPeerToken } = useSandbox({ sandboxApiUrl: SANDBOX_API_URL, }); const onJoinRoomPress = useCallback(async () => { const peerToken = await getSandboxPeerToken("Room", "User"); await joinRoom({ peerToken }); }, [joinRoom, getSandboxPeerToken]); return <button onClick={onJoinRoomPress}>Join room</button>; }

Disconnecting

In order to close connection, use the leaveRoom method from useConnection hook.

import { useConnection } from "@fishjam-cloud/react-client"; import React, { useCallback } from "react"; export function LeaveRoomButton() { const { leaveRoom } = useConnection(); return <button onClick={leaveRoom}>Leave room</button>; }

Next Steps

Now that you're connected to a room, you can explore additional features: