Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FCE-890] Update documentation to use new useConnection hook #54

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/react-native/connecting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ follow our [server setup instructions](/production/server).
In order to connect, you just need to call `joinRoom` method with data from previous step:

```ts
import { joinRoom } from "@fishjam-cloud/react-native-client";
import { useConnection } from "@fishjam-cloud/react-native-client";
const { joinRoom } = useConnection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Can you add a new line after the import? 🙏


await joinRoom(fishjamUrl, peerToken);
```
Expand All @@ -56,7 +57,8 @@ await joinRoom(fishjamUrl, peerToken);
In order to close connection, you have to call `leaveRoom` method.

```ts
import { leaveRoom } from "@fishjam-cloud/react-native-client";
import { useConnection } from "@fishjam-cloud/react-native-client";
const { leaveRoom } = useConnection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Same request 🙏


await leaveRoom();
```
14 changes: 8 additions & 6 deletions docs/react-native/quick-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function StartStreamingButton({
userName: string;
}) {
const { prepareCamera } = useCamera();
const { joinRoom } = useConnection();

const startStreaming = async () => {
const response = await fetch(
Expand All @@ -89,10 +90,10 @@ function StartStreamingButton({

### 3. Check if you are connected

Once you are connected, you can check connection status with `usePeerStatus` hook
Once you are connected, you can check connection status with `useConnection` hook

```ts
const { peerStatus } = usePeerStatus();
const { connectionStatus } = useConnection();
```

### 4. Show other peers
Expand Down Expand Up @@ -161,7 +162,7 @@ npx expo install expo-camera && npx expo prebuild
import { useCallback, useEffect } from "react";
import { Button, StyleSheet, View } from "react-native";
import {
joinRoom,
useConnection,
useCamera,
usePeers,
VideoRendererView,
Expand All @@ -171,7 +172,7 @@ import { useCameraPermissions } from "expo-camera";

function TracksView() {
const { peers } = usePeers();
const { peerStatus } = usePeerStatus();
const { connectionStatus } = useConnection();

const videoTracks = peers.flatMap((peer) =>
peer.tracks.filter((track) => track.type === "Video" && track.isActive),
Expand Down Expand Up @@ -199,6 +200,7 @@ function StartStreamingButton({
userName: string;
}) {
const { prepareCamera } = useCamera();
const { joinRoom } = useConnection();

const startStreaming = async () => {
const response = await fetch(
Expand All @@ -216,7 +218,7 @@ function StartStreamingButton({

export default function HomeScreen() {
const [permission, requestPermission] = useCameraPermissions();
const { peerStatus } = usePeerStatus();
const { connectionStatus } = useConnection();

useEffect(() => {
requestPermission();
Expand All @@ -228,7 +230,7 @@ export default function HomeScreen() {

return (
<SafeAreaView style={styles.container}>
{peerStatus !== "connected" && (
{connectionStatus !== "connected" && (
<StartStreamingButton roomName="*roomName*" userName="*username*" />
)}
<TracksView />
Expand Down
20 changes: 10 additions & 10 deletions docs/react-native/reconnect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ sidebar_position: 7

# Reconnect

If your connection is lost while you are connected to a room, the app will automatically handle the reconnection process. You can monitor these events by utilizing the `useReconnection` hook.
If your connection is lost while you are connected to a room, the app will automatically handle the reconnection process. You can monitor these events by utilizing the `useConnection` hook.

### Example hook that logs the current status to the console:

```ts
import { useEffect, useRef } from "react";
import {
ReconnectionStatus,
useReconnection,
ConnectionStatus,
useConnection,
} from "@fishjam-cloud/react-native-client";

function useLogReconnectionStatus() {
const prevStatus = useRef<ReconnectionStatus>("idle");
const { reconnectionStatus } = useReconnection();
function useLogConnectionStatus() {
const prevStatus = useRef<ConnectionStatus>("idle");
const { connectionStatus } = useConnection();

useEffect(() => {
if (prevStatus.current === reconnectionStatus) return;
prevStatus.current = reconnectionStatus;
if (prevStatus.current === connectionStatus) return;
prevStatus.current = connectionStatus;

switch (reconnectionStatus) {
switch (connectionStatus) {
case "error":
return console.log("Failed to reconnect");
case "reconnecting":
return console.log("Connection is broken, reconnecting...");
default:
return console.log("Connected succesfully");
}
}, [reconnectionStatus]);
}, [connectionStatus]);
}
```