Skip to content

Commit bbf8311

Browse files
authored
FCE-1368/improve and fix snippets (#107)
## Description Update snippets in react client
1 parent 21380af commit bbf8311

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

docs/react/connecting.mdx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ export function LeaveRoomButton() {
4646
// highlight-next-line
4747
const { leaveRoom } = useConnection();
4848

49-
const onLeaveRoomPress = useCallback(() => {
50-
// highlight-next-line
51-
leaveRoom();
52-
}, [leaveRoom]);
53-
54-
return <button onClick={onLeaveRoomPress}>Leave room</button>;
49+
return <button onClick={leaveRoom}>Leave room</button>;
5550
}
5651

5752
```

docs/react/managing-devices.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { useCamera } from "@fishjam-cloud/react-client";
4646
export function CameraControl() {
4747
const { toggleCamera } = useCamera();
4848

49-
return <button onClick={() => toggleCamera()}>Toggle Camera Power</button>;
49+
return <button onClick={() => toggleCamera()}>Toggle Camera Device</button>;
5050
}
5151
```
5252

@@ -76,7 +76,7 @@ export function MicrophoneControl() {
7676
return (
7777
<div>
7878
<button onClick={() => toggleMicrophone()}>
79-
Toggle Microphone Power
79+
Toggle Microphone Device
8080
</button>
8181
<button onClick={() => toggleMicrophoneMute()}>
8282
Toggle Microphone Mute

docs/react/start-streaming.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,37 @@ The code above will make the browser ask the user for camera and microphone perm
3232

3333
To manage users' camera and microphone devices, use the respective [`useCamera`](/api/web/functions/useCamera)
3434
and [`useMicrophone`](/api/web/functions/useMicrophone) hooks.
35-
Both of them has the same API. To keep things simple, let's just use the camera hook.
35+
Both of them has similar API. To keep things simple, we will just use the camera hook.
3636

3737
```tsx
3838
import { useEffect, useRef } from "react";
3939
import { useCamera } from "@fishjam-cloud/react-client";
4040

41-
export function ExampleComponent() {
41+
export function ExampleCameraPreview() {
4242
const videoRef = useRef<HTMLVideoElement>(null);
4343

4444
// highlight-next-line
45-
const { isStreaming, activeDevice, initialize, stream, devices } =
45+
const { activeCamera, selectCamera, cameraStream, cameraDevices } =
4646
// highlight-next-line
4747
useCamera();
4848

4949
useEffect(() => {
5050
if (!videoRef.current) return;
51-
videoRef.current.srcObject = stream ?? null;
52-
}, [stream]);
51+
videoRef.current.srcObject = cameraStream ?? null;
52+
}, [cameraStream]);
5353

5454
return (
5555
<div>
56-
{isStreaming && <p>You are going live!</p>}
57-
<p>Active device: {activeDevice?.label ?? "None"}</p>
58-
<select onChange={(e) => initialize(e.target.value)}>
59-
{devices.map(({ label, deviceId }) => (
56+
<p>Active camera: {activeCamera?.label ?? "None"}</p>
57+
<select onChange={(e) => selectCamera(e.target.value)}>
58+
{cameraDevices.map(({ label, deviceId }) => (
6059
<option key={deviceId} value={deviceId}>
6160
{label}
6261
</option>
6362
))}
6463
</select>
6564
// highlight-next-line
66-
{stream && <video ref={videoRef} autoPlay />}
65+
{cameraStream && <video ref={videoRef} autoPlay />}
6766
</div>
6867
);
6968
}

docs/react/stream-middleware.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ export function CameraWithBlurEffect() {
3838
const videoRef = useRef<HTMLVideoElement>(null);
3939

4040
// highlight-next-line
41-
const { stream, currentMiddleware, setTrackMiddleware } = useCamera();
41+
const { cameraStream, currentCameraMiddleware, setCameraTrackMiddleware } =
42+
// highlight-next-line
43+
useCamera();
4244

4345
useEffect(() => {
4446
if (!videoRef.current) return;
45-
videoRef.current.srcObject = stream ?? null;
46-
}, [stream]);
47+
videoRef.current.srcObject = cameraStream ?? null;
48+
}, [cameraStream]);
4749

4850
// Define blur middleware
4951
const blurMiddleware: TrackMiddleware = useCallback(
@@ -60,12 +62,12 @@ export function CameraWithBlurEffect() {
6062
);
6163

6264
// Check if the current middleware is blur
63-
const isBlurEnabled = currentMiddleware === blurMiddleware;
65+
const isBlurEnabled = currentCameraMiddleware === blurMiddleware;
6466

6567
// Toggle blur effect
6668
const toggleBlur = () => {
6769
// highlight-next-line
68-
setTrackMiddleware(isBlurEnabled ? null : blurMiddleware);
70+
setCameraTrackMiddleware(isBlurEnabled ? null : blurMiddleware);
6971
};
7072

7173
return (
@@ -74,7 +76,7 @@ export function CameraWithBlurEffect() {
7476
{isBlurEnabled ? "Disable Blur" : "Enable Blur"}
7577
</button>
7678

77-
{stream && <video ref={videoRef} />}
79+
{cameraStream && <video ref={videoRef} autoPlay />}
7880
</>
7981
);
8082
}

0 commit comments

Comments
 (0)