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 { 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 { useCallback } from "react";

export function LeaveRoomButton() {
const { leaveRoom } = useConnection();

const onLeaveRoomPress = useCallback(() => {
leaveRoom();
}, [leaveRoom]);

return <button onClick={onLeaveRoomPress}>Leave room</button>;
}