Skip to content

Commit d4e0969

Browse files
authored
Use sandbox api in moq (#69)
1 parent c5d19f4 commit d4e0969

6 files changed

Lines changed: 51 additions & 15 deletions

File tree

moq-demo/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ yarn dev
1919
3. Open the URL printed by Vite (e.g. `http://localhost:5173`).
2020

2121
4. Provide a **Fishjam ID** in one of two ways:
22+
2223
- Pass it as a query parameter: `http://localhost:5173?fishjamId=<your-id>`
2324
- Leave it out — a **Fishjam ID** input field will appear in the UI so you can enter it at runtime.
2425

25-
5. Enter a stream name and click **Start Streaming** to publish, or **Connect to Stream** to watch.
26+
5. Provide the **Sandbox API URL**:
27+
28+
- Pass it as a query parameter: `http://localhost:5173?fishjamId=<your-id>&sandboxApiUrl=https://fishjam.io/api/v1/connect/<your-key>/room-manager`
29+
- Or enter it in the UI at runtime.
30+
31+
6. Enter a stream name and click **Start Streaming** to publish, or **Connect to Stream** to watch.

moq-demo/src/App.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { createSignal, Show } from "solid-js";
22
import Streamer from "./Streamer";
33
import Viewer from "./Viewer";
4-
import { fishjamId as configFishjamId } from "./config";
4+
import {
5+
fishjamId as configFishjamId,
6+
SANDBOX_API_URL as configSandboxApiUrl,
7+
} from "./config";
58

69
export default function App() {
710
const [streamName, setStreamName] = createSignal("my-stream");
811
const [fishjamId, setFishjamId] = createSignal(configFishjamId);
12+
const [sandboxApiUrl, setSandboxApiUrl] = createSignal(configSandboxApiUrl);
913

1014
return (
1115
<div class="min-h-screen bg-background p-8">
@@ -44,12 +48,38 @@ export default function App() {
4448
/>
4549
</div>
4650
</Show>
51+
<Show when={!configSandboxApiUrl}>
52+
<div class="space-y-2">
53+
<label
54+
class="text-sm font-medium leading-none"
55+
for="sandbox-api-url"
56+
>
57+
Sandbox API URL
58+
</label>
59+
<input
60+
id="sandbox-api-url"
61+
type="text"
62+
value={sandboxApiUrl()}
63+
onInput={(e) => setSandboxApiUrl(e.currentTarget.value)}
64+
placeholder="https://cloud.fishjam.work/api/v1/connect/<id>/room-manager"
65+
class="border-input bg-input/30 flex h-9 w-full rounded-md border px-3 py-1 text-sm shadow-xs outline-none transition-colors placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
66+
/>
67+
</div>
68+
</Show>
4769
</div>
4870
</div>
4971
</div>
5072
<div class="mx-auto max-w-7xl grid grid-cols-1 gap-8 lg:grid-cols-2">
51-
<Streamer streamName={streamName()} fishjamId={fishjamId()} />
52-
<Viewer streamName={streamName()} fishjamId={fishjamId()} />
73+
<Streamer
74+
streamName={streamName()}
75+
fishjamId={fishjamId()}
76+
sandboxApiUrl={sandboxApiUrl()}
77+
/>
78+
<Viewer
79+
streamName={streamName()}
80+
fishjamId={fishjamId()}
81+
sandboxApiUrl={sandboxApiUrl()}
82+
/>
5383
</div>
5484
</div>
5585
);

moq-demo/src/Streamer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { createSignal, Show } from "solid-js";
22
import "@moq/publish/ui";
33
import "@moq/publish/element";
4-
import { MOQ_BASE_URL, FISHJAM_API_BASE_URL } from "./config";
4+
import { MOQ_BASE_URL } from "./config";
55

66
interface Props {
77
streamName: string;
88
fishjamId: string;
9+
sandboxApiUrl: string;
910
}
1011

1112
export default function Streamer(props: Props) {
@@ -19,7 +20,7 @@ export default function Streamer(props: Props) {
1920
setLoading(true);
2021
try {
2122
const res = await fetch(
22-
`${FISHJAM_API_BASE_URL}/${props.fishjamId}/room-manager/moq/${encodeURIComponent(props.streamName)}/publisher`,
23+
`${props.sandboxApiUrl}/moq/${encodeURIComponent(props.streamName)}/publisher`,
2324
);
2425
if (!res.ok) throw new Error(await res.text());
2526
const { token } = (await res.json()) as { token: string };

moq-demo/src/Viewer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { createSignal, Show } from "solid-js";
22
import "@moq/watch/ui";
33
import "@moq/watch/element";
4-
import { MOQ_BASE_URL, FISHJAM_API_BASE_URL } from "./config";
4+
import { MOQ_BASE_URL } from "./config";
55

66
interface Props {
77
streamName: string;
88
fishjamId: string;
9+
sandboxApiUrl: string;
910
}
1011

1112
export default function Viewer(props: Props) {
@@ -19,7 +20,7 @@ export default function Viewer(props: Props) {
1920
setLoading(true);
2021
try {
2122
const res = await fetch(
22-
`${FISHJAM_API_BASE_URL}/${props.fishjamId}/room-manager/moq/${encodeURIComponent(props.streamName)}/subscriber`,
23+
`${props.sandboxApiUrl}/moq/${encodeURIComponent(props.streamName)}/subscriber`,
2324
);
2425
if (!res.ok) throw new Error(await res.text());
2526
const { token } = (await res.json()) as { token: string };

moq-demo/src/config.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
const params = new URLSearchParams(window.location.search);
22

33
export const fishjamId =
4-
params.get("fishjamId") ??
5-
import.meta.env.VITE_FISHJAM_ID ??
6-
"";
4+
params.get("fishjamId") ?? import.meta.env.VITE_FISHJAM_ID ?? "";
5+
6+
export const SANDBOX_API_URL =
7+
params.get("sandboxApiUrl") ?? import.meta.env.VITE_SANDBOX_API_URL ?? "";
78

89
export const MOQ_BASE_URL =
910
params.get("baseUrl") ??
1011
import.meta.env.VITE_MOQ_BASE_URL ??
1112
"https://moq.fishjam.work:443";
12-
13-
export const FISHJAM_API_BASE_URL =
14-
import.meta.env.VITE_FISHJAM_API_BASE_URL ??
15-
"https://cloud.fishjam.io/api/v1/connect";

moq-demo/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
interface ImportMetaEnv {
44
readonly VITE_FISHJAM_ID?: string;
5+
readonly VITE_SANDBOX_API_URL?: string;
56
readonly VITE_MOQ_BASE_URL?: string;
67
readonly VITE_FISHJAM_API_BASE_URL?: string;
78
}

0 commit comments

Comments
 (0)