Skip to main content

Connecting

Prerequisites

In order to connect, you need a Peer Token and the Fishjam URL.

Connecting

Use the useConnection hook to get the joinRoom function.

import { useConnection } from "@fishjam-cloud/react-client"; import React, { useCallback } from "react"; export function JoinRoomButton() { const { joinRoom } = useConnection(); const onJoinRoomPress = useCallback(async () => { await joinRoom({ url: FISHJAM_URL, peerToken: PEER_TOKEN, }); }, [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>; }