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"; importReact , {useCallback } from "react"; export functionJoinRoomButton () { const {joinRoom } =useConnection (); constonJoinRoomPress =useCallback (async () => { awaitjoinRoom ({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"; importReact , {useCallback } from "react"; export functionLeaveRoomButton () { const {leaveRoom } =useConnection (); return <button onClick ={leaveRoom }>Leave room</button >; }