|
| 1 | +--- |
| 2 | +type: explanation |
| 3 | +sidebar_position: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +# React Examples |
| 7 | + |
| 8 | +_Runnable reference apps demonstrating common Fishjam use cases in React_ |
| 9 | + |
| 10 | +Each example is a standalone React application you can run locally and use as a starting point for your own project. |
| 11 | +All examples use `@fishjam-cloud/react-client` and require a Fishjam ID from the [Fishjam Dashboard](https://fishjam.io/app). |
| 12 | + |
| 13 | +| Example | What it demonstrates | |
| 14 | +| ----------------------------------- | ---------------------------------------------------------------------- | |
| 15 | +| [Minimal React](#minimal-react) | Simplest video call — join a room, camera, mic, screen share | |
| 16 | +| [Audio Only](#audio-only) | Voice chat with no video and microphone device selection | |
| 17 | +| [Text Chat](#text-chat) | Peer-to-peer messaging over WebRTC data channels | |
| 18 | +| [Livestreaming](#livestreaming) | One broadcaster, many viewers with separate streamer/viewer UIs | |
| 19 | +| [Minimal Smelter](#minimal-smelter) | Custom video overlays using the Smelter rendering engine | |
| 20 | +| [Fishjam Chat](#fishjam-chat) | Full-featured conferencing app with background blur and screen sharing | |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Minimal React |
| 25 | + |
| 26 | +The simplest way to get a video call working in the browser — joining a room, displaying your own camera feed, and showing remote participants. Start here if you're new to Fishjam on the web. |
| 27 | + |
| 28 | +**Demonstrates:** |
| 29 | + |
| 30 | +- Wrapping your app in `FishjamProvider` |
| 31 | +- Connecting to a room with `useConnection` |
| 32 | +- Accessing local and remote peers with `usePeers` |
| 33 | +- Enabling camera and microphone with `useCamera` and `useMicrophone` |
| 34 | +- Starting screen sharing with `useScreenShare` |
| 35 | +- Rendering streams with `VideoPlayer` and `AudioPlayer` components |
| 36 | + |
| 37 | +### Running the example |
| 38 | + |
| 39 | +```bash |
| 40 | +cd minimal-react |
| 41 | +yarn install |
| 42 | +yarn dev |
| 43 | +``` |
| 44 | + |
| 45 | +The room component uses `usePeers` to retrieve all participants and renders their video streams using `VideoPlayer` and audio with `AudioPlayer`. |
| 46 | + |
| 47 | +:::note |
| 48 | +This example requires a **peer token** to connect. You need to obtain one yourself — either via the [Sandbox API](../how-to/features/sandbox-api-testing#step-2-create-a-room-and-get-peer-tokens) for quick testing, or by setting up your own backend with the [Fishjam Server SDK](../tutorials/backend-quick-start). |
| 49 | +::: |
| 50 | + |
| 51 | +Browse the full source: [minimal-react on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/minimal-react) |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +## Audio Only |
| 56 | + |
| 57 | +A voice-only room with no video — demonstrates how to initialize Fishjam with audio exclusively and let users pick their microphone device before joining. |
| 58 | + |
| 59 | +**Demonstrates:** |
| 60 | + |
| 61 | +- Audio-only initialization with `useInitializeDevices` (`enableVideo: false`) |
| 62 | +- Microphone device selection from available inputs |
| 63 | +- Rendering a peer list with audio playback via `AudioPlayer` |
| 64 | + |
| 65 | +### Running the example |
| 66 | + |
| 67 | +```bash |
| 68 | +cd audio-only |
| 69 | +yarn install |
| 70 | +yarn dev |
| 71 | +``` |
| 72 | + |
| 73 | +Setting `enableVideo: false` in `useInitializeDevices` skips camera initialization entirely, keeping the session lightweight for voice-only use cases. |
| 74 | + |
| 75 | +Browse the full source: [audio-only on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/audio-only) |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Text Chat |
| 80 | + |
| 81 | +Demonstrates peer-to-peer text messaging over WebRTC data channels — no separate messaging server required. Messages are sent directly between peers inside the Fishjam room. |
| 82 | + |
| 83 | +**Demonstrates:** |
| 84 | + |
| 85 | +- Initializing a data channel with `useDataChannel` |
| 86 | +- Publishing messages with `publishData` |
| 87 | +- Receiving incoming messages with `subscribeData` |
| 88 | +- Encoding and decoding message payloads with `TextEncoder` and `TextDecoder` |
| 89 | + |
| 90 | +### Running the example |
| 91 | + |
| 92 | +```bash |
| 93 | +cd text-chat |
| 94 | +yarn install |
| 95 | +yarn dev |
| 96 | +``` |
| 97 | + |
| 98 | +Messages are `Uint8Array` payloads encoded and decoded with JSON and `TextEncoder`/`TextDecoder`. The `useDataChannel` hook wires together `publishData` for sending and `subscribeData` for receiving. |
| 99 | + |
| 100 | +Browse the full source: [text-chat on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/text-chat) |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## Livestreaming |
| 105 | + |
| 106 | +A focused livestreaming example with two separate modes: a streamer who broadcasts video and audio, and a viewer who watches the stream. Token management is handled via the `useSandbox` hook. |
| 107 | + |
| 108 | +**Demonstrates:** |
| 109 | + |
| 110 | +- Broadcasting with `useLivestreamStreamer` |
| 111 | +- Watching a stream with `useLivestreamViewer` |
| 112 | +- Separate broadcaster and viewer UIs within one application |
| 113 | +- Obtaining peer tokens with `useSandbox` |
| 114 | + |
| 115 | +### Running the example |
| 116 | + |
| 117 | +```bash |
| 118 | +cd livestreaming |
| 119 | +yarn install |
| 120 | +yarn dev |
| 121 | +``` |
| 122 | + |
| 123 | +The streamer side uses `useLivestreamStreamer` to publish camera and audio tracks, while the viewer side uses `useLivestreamViewer` to connect and render the incoming stream. |
| 124 | + |
| 125 | +Browse the full source: [livestreaming on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/livestreaming) |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## Minimal Smelter |
| 130 | + |
| 131 | +Shows how to apply custom video overlays to a camera feed using the Smelter rendering engine — a text label composited directly onto the outgoing video stream. |
| 132 | + |
| 133 | +**Demonstrates:** |
| 134 | + |
| 135 | +- Creating a custom video source with `useCustomSource` |
| 136 | +- Initializing the Smelter engine with `useSmelter` |
| 137 | +- Registering inputs and outputs with `registerInput`/`registerOutput` |
| 138 | +- Compositing a text overlay on top of a live camera feed |
| 139 | + |
| 140 | +### Running the example |
| 141 | + |
| 142 | +```bash |
| 143 | +cd minimal-smelter |
| 144 | +yarn install |
| 145 | +yarn dev |
| 146 | +``` |
| 147 | + |
| 148 | +:::important |
| 149 | +Smelter requires WebAssembly support — use a modern browser. |
| 150 | +::: |
| 151 | + |
| 152 | +The `useSmelter` hook manages the Smelter engine lifecycle. `registerInput` connects the local camera feed and `registerOutput` routes the composited result back into Fishjam as a custom track. |
| 153 | + |
| 154 | +:::note |
| 155 | +This example requires a **peer token** to connect. You need to obtain one yourself — either via the [Sandbox API](../how-to/features/sandbox-api-testing#step-2-create-a-room-and-get-peer-tokens) for quick testing, or by setting up your own backend with the [Fishjam Server SDK](../tutorials/backend-quick-start). |
| 156 | +::: |
| 157 | + |
| 158 | +Browse the full source: [minimal-smelter on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/minimal-smelter) |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## Fishjam Chat |
| 163 | + |
| 164 | +A full-featured conferencing application covering camera, microphone, screen sharing, background blur via a camera track middleware, and a settings panel for device selection. |
| 165 | + |
| 166 | +**Demonstrates:** |
| 167 | + |
| 168 | +- Connecting to a room with `useConnection` |
| 169 | +- Managing camera and microphone with `useCamera` and `useMicrophone` |
| 170 | +- Screen sharing with `useScreenShare` |
| 171 | +- Applying real-time background blur using a MediaPipe camera track middleware |
| 172 | +- Device selection in a settings panel |
| 173 | + |
| 174 | +### Running the example |
| 175 | + |
| 176 | +```bash |
| 177 | +cd fishjam-chat |
| 178 | +yarn install |
| 179 | +yarn dev |
| 180 | +``` |
| 181 | + |
| 182 | +Background blur is applied as a camera track middleware that processes each video frame with MediaPipe before the track is sent to other participants. Removing the middleware disables the effect without reconnecting. |
| 183 | + |
| 184 | +Browse the full source: [fishjam-chat on GitHub](https://github.com/fishjam-cloud/examples/tree/main/web-react/fishjam-chat) |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +## Next steps |
| 189 | + |
| 190 | +- Follow the [React Quick Start](../tutorials/react-quick-start) if you haven't set up a project yet |
| 191 | +- Learn how to [work with data channels](../how-to/client/data-channels) |
| 192 | +- Learn how to [implement screen sharing](../how-to/client/screensharing) |
0 commit comments