Skip to content

Commit 6d28d19

Browse files
Magmusacyczerwiukk
andauthored
Change useSandbox hook api (#525)
## Description Changed the api of useSandbox hook as well as updated e2e livestream tests to support this new api ## Motivation and Context we've changed how users communicate with room manager ## Documentation impact - [X] Documentation update required - [ ] Documentation updated [in another PR](_) - [ ] No documentation update required ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [X] Breaking change (fix or feature that would cause existing functionality to not work as expected) --------- Co-authored-by: adrian <33912477+czerwiukk@users.noreply.github.com>
1 parent 3f6bc2c commit 6d28d19

14 files changed

Lines changed: 63 additions & 29 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: yarn test:e2e
4747
env:
4848
VITE_FISHJAM_URL: ${{ secrets.TEST_FISHJAM_URL }}
49-
49+
VITE_SANDBOX_API_URL: ${{ secrets.TEST_SANDBOX_API_URL }}
5050
- uses: actions/upload-artifact@v4
5151
if: always()
5252
with:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export const FISHJAM_URL =
22
import.meta.env.VITE_FISHJAM_URL || "http://localhost:4000";
3+
export const SANDBOX_API_URL =
4+
import.meta.env.VITE_SANDBOX_API_URL || "http://localhost:4000";

e2e-tests/livestream-client/src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import {
66
import { LivestreamError } from "@fishjam-cloud/ts-client";
77
import { useEffect, useRef, useState } from "react";
88

9+
import { SANDBOX_API_URL } from "../config";
910
import { createCanvasStream, stopCanvasStream } from "./canvasStream";
1011

1112
const roomName =
1213
new URLSearchParams(window.location.search).get("room") ?? "livestream-e2e";
1314

1415
export function App() {
15-
const { getSandboxLivestream, getSandboxViewerToken } = useSandbox();
16+
const { getSandboxLivestream, getSandboxViewerToken } = useSandbox({
17+
sandboxApiUrl: SANDBOX_API_URL,
18+
});
1619
const viewer = useLivestreamViewer();
1720
const streamer = useLivestreamStreamer();
1821

e2e-tests/react-client/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
const fishjamUrl = process.env.VITE_FISHJAM_URL;
2+
const sandboxApiUrl = process.env.VITE_SANDBOX_API_URL;
23

34
if (!fishjamUrl) {
45
throw new Error("VITE_FISHJAM_URL environment variable is not set");
56
}
67

8+
if (!sandboxApiUrl) {
9+
throw new Error("VITE_SANDBOX_API_URL environment variable is not set");
10+
}
11+
712
export const FISHJAM_URL = fishjamUrl;
13+
export const SANDBOX_API_URL = sandboxApiUrl;

e2e-tests/react-client/scenarios/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { Page } from "@playwright/test";
2-
import { v4 as uuidv4 } from "uuid";
32
import { expect, test } from "@playwright/test";
3+
import { v4 as uuidv4 } from "uuid";
4+
5+
import { SANDBOX_API_URL } from "../config.ts";
46

5-
import { FISHJAM_URL } from "../config.ts"
67

78
export const joinRoomAndAddScreenShare = async (
89
page: Page,
@@ -83,7 +84,7 @@ export const createPeer = async (
8384
) =>
8485
await test.step("Create room", async () => {
8586
const roomRequest = await page.request.get(
86-
`${FISHJAM_URL}/room-manager?roomName=${roomId}&peerName=${uuidv4()}`,
87+
`${SANDBOX_API_URL}?roomName=${roomId}&peerName=${uuidv4()}`,
8788
);
8889
return roomRequest;
8990
});

e2e-tests/webrtc-client/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@ function getFishjamUrl() {
66
}
77
}
88

9+
function getSandboxApiUrl() {
10+
try {
11+
return import.meta.env.VITE_SANDBOX_API_URL;
12+
} catch {
13+
return process.env.VITE_SANDBOX_API_URL;
14+
}
15+
}
16+
917
const fishjamUrl = getFishjamUrl();
18+
const sandboxApiUrl = getSandboxApiUrl();
1019

1120
if (!fishjamUrl) {
1221
throw new Error("VITE_FISHJAM_URL environment variable is not set");
1322
}
1423

15-
export const FISHJAM_URL = fishjamUrl;
24+
if (!sandboxApiUrl) {
25+
throw new Error("VITE_SANDBOX_API_URL environment variable is not set");
26+
}
1627

28+
export const FISHJAM_URL = fishjamUrl;
29+
export const SANDBOX_API_URL = sandboxApiUrl;
1730
export const FISHJAM_WS_URL = `${FISHJAM_URL}/socket/peer/websocket`;

e2e-tests/webrtc-client/scenarios/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Page, TestInfo } from "@playwright/test";
22
import { expect, test } from "@playwright/test";
33
import { v4 as uuidv4 } from "uuid";
44

5-
import { FISHJAM_URL } from "../config.ts";
5+
import { SANDBOX_API_URL } from "../config.ts";
66

77
const TO_PASS_TIMEOUT_MILLIS = 10 * 1000;
88

@@ -12,7 +12,7 @@ const expectWithLongerTimeout = expect.configure({
1212

1313
export const createPeer = async (page: Page, peerName: string, roomName: string) =>
1414
await test.step("Create peer", async () => {
15-
return await page.request.get(`${FISHJAM_URL}/room-manager?roomName=${roomName}&peerName=${peerName}`);
15+
return await page.request.get(`${SANDBOX_API_URL}?roomName=${roomName}&peerName=${peerName}`);
1616
});
1717

1818
export const createAndJoinPeer = async (
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
EXPO_PUBLIC_FISHJAM_ID=
2-
EXPO_PUBLIC_VIDEOROOM_STAGING_SANDBOX_URL=
2+
EXPO_PUBLIC_VIDEOROOM_STAGING_SANDBOX_URL=
3+
EXPO_PUBLIC_SANDBOX_API_URL=

examples/mobile-client/fishjam-chat/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
Copy `.env.example` to `.env` in the `examples/mobile-client/fishjam-chat` directory and fill in the required value:
66

7-
- `EXPO_PUBLIC_FISHJAM_ID` - Fishjam ID for production environment
7+
- `EXPO_PUBLIC_FISHJAM_ID` - Fishjam ID for connecting to fishjam platform
8+
- `EXPO_PUBLIC_SANDBOX_API_URL` - Sandbox API URL used by `useSandbox` to create rooms and fetch peer, viewer, and streamer tokens
89

9-
You can find the value for this variable by creating an account on [fishjam.io](https://fishjam.io) and copying it from the sandbox dashboard.
10+
You can find these values in the Fishjam dashboard:
11+
12+
- `Fishjam ID` is available at [fishjam.io/app](https://fishjam.io/app).
13+
- `Sandbox API url` is available at [fishjam.io/app/sandbox](https://fishjam.io/app/sandbox).
1014

1115
There also exists this additional environment variable, which is used for internal testing purposes:
1216

examples/mobile-client/fishjam-chat/app/livestream/screen-sharing.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
useScreenShare,
66
} from '@fishjam-cloud/react-native-client';
77
import { useLocalSearchParams } from 'expo-router';
8-
import React, { useCallback, useEffect, useState } from 'react';
8+
import { useCallback, useEffect, useState } from 'react';
99
import { StyleSheet, Text, View } from 'react-native';
1010
import { SafeAreaView } from 'react-native-safe-area-context';
1111

@@ -19,7 +19,9 @@ export default function LivestreamScreenSharingScreen() {
1919
}>();
2020

2121
const { initializeDevices } = useInitializeDevices();
22-
const { getSandboxLivestream } = useSandbox();
22+
const { getSandboxLivestream } = useSandbox({
23+
sandboxApiUrl: process.env.EXPO_PUBLIC_SANDBOX_API_URL ?? '',
24+
});
2325
const { connect, disconnect, isConnected, error } = useLivestreamStreamer();
2426
const {
2527
startStreaming: startScreenCapture,

0 commit comments

Comments
 (0)