Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit 53b6e99

Browse files
authored
Make FishjamRoom use id instead of url to join room (#479)
## Description Change the implementation of FishjamRoom so that it uses fishamId instead of url to connect to the room. ## Motivation and Context We update the FishjamRoom component so that it uses the new way of joining the fishjam room. ## How has this been tested? I've tested this in the fishjam-chat app ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist: - [ ] My code follows the code style of this project. - [x] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly.
1 parent 7b79020 commit 53b6e99

2 files changed

Lines changed: 25 additions & 38 deletions

File tree

internal/fishjam-chat/screens/ConnectWithFishjamRoom.tsx

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
1-
import { FishjamRoom } from '@fishjam-cloud/react-native-client';
1+
import { FishjamRoom, useSandbox } from '@fishjam-cloud/react-native-client';
22
import { useEffect, useState } from 'react';
3-
import { joinRoomWithRoomManager } from '../utils/roomManager';
43
import { ActivityIndicator, StyleSheet } from 'react-native';
54

6-
type RoomData = {
7-
url: string;
8-
peerToken: string;
9-
};
10-
115
export const ConnectWithFishjamRoom = () => {
12-
const [roomData, setRoomData] = useState<RoomData | null>(null);
6+
const fishjamId = process.env.EXPO_PUBLIC_FISHJAM_ID ?? '';
7+
const { getSandboxPeerToken } = useSandbox({ fishjamId: fishjamId });
8+
const [peerToken, setPeerToken] = useState<string | null>(null);
139

1410
useEffect(() => {
15-
const fetchRoomData = async () => {
11+
const connect = async () => {
1612
try {
17-
const { fishjamUrl, token } = await joinRoomWithRoomManager(
18-
'https://room.fishjam.work/api/rooms',
19-
'test-room',
20-
'test-user',
21-
);
22-
setRoomData({
23-
url: fishjamUrl,
24-
peerToken: token,
25-
});
26-
} catch {
27-
setRoomData(null);
13+
const uniqPeerName = `test-user-${new Date().getTime()}${Math.random() * 1000}`;
14+
const peerToken = await getSandboxPeerToken('test-room', uniqPeerName);
15+
setPeerToken(peerToken);
16+
} catch (e) {
17+
console.error('Error connecting to Fishjam', e);
2818
}
2919
};
30-
fetchRoomData();
31-
}, []);
3220

33-
if (!roomData) {
21+
connect();
22+
}, [getSandboxPeerToken]);
23+
24+
if (!peerToken) {
3425
return <ActivityIndicator size="large" style={styles.indicator} />;
3526
}
3627

37-
return (
38-
<FishjamRoom fishjamUrl={roomData.url} peerToken={roomData.peerToken} />
39-
);
28+
return <FishjamRoom fishjamId={fishjamId} peerToken={peerToken} />;
4029
};
4130

4231
const styles = StyleSheet.create({

packages/react-native-client/src/components/FishjamRoom/index.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useEffect } from 'react';
2-
import { joinRoom, leaveRoom } from '../../common/client';
32
import { useCamera } from '../../hooks/useCamera';
3+
import { useConnection } from '../../hooks/useConnection';
44
import { VideosGrid } from './VideosGrid';
55
import { SafeAreaView } from 'react-native';
66

77
export type FishjamRoomProps = {
88
/**
9-
* URL to your fishjam instance
9+
* ID of your fishjam instance
1010
*/
11-
fishjamUrl: string;
11+
fishjamId: string;
1212
/**
1313
* Peer Token
1414
*/
@@ -23,21 +23,22 @@ export type FishjamRoomProps = {
2323
* import { FishjamRoom } from '@fishjam-cloud/react-native-client';
2424
* import React from 'react';
2525
*
26-
* const FISHJAM_URL = 'https://fishjam.io/your_fishjam';
26+
* const FISHJAM_ID = 'your-fishjam_id';
2727
* const PEER_TOKEN = 'your-peer-token';
2828
*
2929
* <FishjamRoom
30-
* fishjamUrl={FISHJAM_URL}
30+
* fishjamId={FISHJAM_ID}
3131
* peerToken={PEER_TOKEN}
3232
* />
3333
* ```
3434
* @category Components
3535
* @param {object} props
36-
* @param {string} props.fishjamUrl
36+
* @param {string} props.fishjamId
3737
* @param {string} props.peerToken
3838
*/
39-
export const FishjamRoom = ({ fishjamUrl, peerToken }: FishjamRoomProps) => {
39+
export const FishjamRoom = ({ fishjamId, peerToken }: FishjamRoomProps) => {
4040
const { prepareCamera } = useCamera();
41+
const { leaveRoom, joinRoom } = useConnection();
4142

4243
useEffect(() => {
4344
const join = async () => {
@@ -47,10 +48,7 @@ export const FishjamRoom = ({ fishjamUrl, peerToken }: FishjamRoomProps) => {
4748
quality: 'HD169',
4849
cameraEnabled: true,
4950
});
50-
await joinRoom(fishjamUrl, peerToken, {
51-
peer: {},
52-
server: {},
53-
});
51+
await joinRoom({ fishjamId, peerToken });
5452
} catch (e) {
5553
console.warn(e);
5654
}
@@ -59,7 +57,7 @@ export const FishjamRoom = ({ fishjamUrl, peerToken }: FishjamRoomProps) => {
5957
return () => {
6058
leaveRoom();
6159
};
62-
}, [fishjamUrl, peerToken, prepareCamera]);
60+
}, [fishjamId, peerToken, prepareCamera, joinRoom, leaveRoom]);
6361

6462
return (
6563
<SafeAreaView>

0 commit comments

Comments
 (0)