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 will have access to the Sandbox environment as part of the Mini Jar plan. While using the Sandbox environment, you can use the Sandbox API to generate peer tokens for testing or development purposes. 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.

// The `useSandbox` hook gets the fishjamId from FishjamProvider // It will work ONLY with the FISHJAM_ID of the Sandbox environment const { getSandboxPeerToken } = useSandbox(); 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(); const onJoinRoomPress = useCallback(async () => { const peerToken = await getSandboxPeerToken("Room", "User"); await joinRoom({ peerToken }); }, [joinRoom]); 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: