fix: redirect to stream after starting it

This commit is contained in:
Alejandro Gomez 2023-06-24 13:12:18 +02:00
parent 15ac0cacb3
commit 28e8b5fffa
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
4 changed files with 221 additions and 133 deletions

View File

@ -8,6 +8,7 @@
"@testing-library/react": "^13.0.0", "@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1", "@testing-library/user-event": "^13.2.1",
"hls.js": "^1.4.6", "hls.js": "^1.4.6",
"nostr-tools": "^1.12.0",
"qr-code-styling": "^1.6.0-rc.1", "qr-code-styling": "^1.6.0-rc.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@ -6,7 +6,13 @@ import AsyncButton from "./async-button";
import { System } from "index"; import { System } from "index";
import { findTag } from "utils"; import { findTag } from "utils";
export function NewStream({ ev, onFinish }: { ev?: NostrEvent, onFinish: () => void }) { export function NewStream({
ev,
onFinish,
}: {
ev?: NostrEvent;
onFinish: (ev: NostrEvent) => void;
}) {
const [title, setTitle] = useState(findTag(ev, "title") ?? ""); const [title, setTitle] = useState(findTag(ev, "title") ?? "");
const [summary, setSummary] = useState(findTag(ev, "summary") ?? ""); const [summary, setSummary] = useState(findTag(ev, "summary") ?? "");
const [image, setImage] = useState(findTag(ev, "image") ?? ""); const [image, setImage] = useState(findTag(ev, "image") ?? "");
@ -33,66 +39,82 @@ export function NewStream({ ev, onFinish }: { ev?: NostrEvent, onFinish: () => v
async function publishStream() { async function publishStream() {
const pub = await EventPublisher.nip7(); const pub = await EventPublisher.nip7();
if (pub) { if (pub) {
const evNew = await pub.generic(eb => { const evNew = await pub.generic((eb) => {
const now = unixNow(); const now = unixNow();
const dTag = findTag(ev, "d") ?? now.toString(); const dTag = findTag(ev, "d") ?? now.toString();
return eb.kind(30_311) return eb
.kind(30_311)
.tag(["d", dTag]) .tag(["d", dTag])
.tag(["title", title]) .tag(["title", title])
.tag(["summary", summary]) .tag(["summary", summary])
.tag(["image", image]) .tag(["image", image])
.tag(["streaming", stream]) .tag(["streaming", stream])
.tag(["status", "live"]) .tag(["status", "live"]);
}); });
console.debug(evNew); console.debug(evNew);
System.BroadcastEvent(evNew); //System.BroadcastEvent(evNew);
onFinish(); onFinish(evNew);
} }
} }
return <div className="new-stream"> return (
<h3> <div className="new-stream">
{ev ? "Edit Stream" : "New Stream"} <h3>{ev ? "Edit Stream" : "New Stream"}</h3>
</h3>
<div> <div>
<p> <p>Title</p>
Title
</p>
<div className="input"> <div className="input">
<input type="text" placeholder="What are we steaming today?" value={title} onChange={e => setTitle(e.target.value)} /> <input
type="text"
placeholder="What are we steaming today?"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
</div> </div>
</div> </div>
<div> <div>
<p> <p>Summary</p>
Summary
</p>
<div className="input"> <div className="input">
<input type="text" placeholder="A short description of the content" value={summary} onChange={e => setSummary(e.target.value)} /> <input
type="text"
placeholder="A short description of the content"
value={summary}
onChange={(e) => setSummary(e.target.value)}
/>
</div> </div>
</div> </div>
<div> <div>
<p> <p>Cover image</p>
Cover image
</p>
<div className="input"> <div className="input">
<input type="text" placeholder="https://" value={image} onChange={e => setImage(e.target.value)} /> <input
type="text"
placeholder="https://"
value={image}
onChange={(e) => setImage(e.target.value)}
/>
</div> </div>
</div> </div>
<div> <div>
<p> <p>Stream Url</p>
Stream Url
</p>
<div className="input"> <div className="input">
<input type="text" placeholder="https://" value={stream} onChange={e => setStream(e.target.value)} /> <input
type="text"
placeholder="https://"
value={stream}
onChange={(e) => setStream(e.target.value)}
/>
</div> </div>
<small> <small>Stream type should be HLS</small>
Stream type should be HLS
</small>
</div> </div>
<div> <div>
<AsyncButton type="button" className="btn btn-primary" disabled={!isValid} onClick={publishStream}> <AsyncButton
type="button"
className="btn btn-primary"
disabled={!isValid}
onClick={publishStream}
>
{ev ? "Save" : "Start Stream"} {ev ? "Save" : "Start Stream"}
</AsyncButton> </AsyncButton>
</div> </div>
</div> </div>
);
} }

View File

@ -1,6 +1,7 @@
import { Icon } from "element/icon"; import { Icon } from "element/icon";
import "./layout.css"; import "./layout.css";
import { EventPublisher } from "@snort/system"; import { EventPublisher, NostrEvent } from "@snort/system";
import { nip19 } from "nostr-tools";
import { Outlet, useNavigate } from "react-router-dom"; import { Outlet, useNavigate } from "react-router-dom";
import AsyncButton from "element/async-button"; import AsyncButton from "element/async-button";
import { Login } from "index"; import { Login } from "index";
@ -25,33 +26,54 @@ export function LayoutPage() {
function loggedIn() { function loggedIn() {
if (!login) return; if (!login) return;
return <> return (
<button type="button" className="btn btn-primary" onClick={() => setNewStream(true)}> <>
<button
type="button"
className="btn btn-primary"
onClick={() => setNewStream(true)}
>
New Stream New Stream
<Icon name="signal" /> <Icon name="signal" />
</button> </button>
<Profile pubkey={login.pubkey} options={{ <Profile
showName: false pubkey={login.pubkey}
}} /> options={{
showName: false,
}}
/>
</> </>
);
} }
function loggedOut() { function loggedOut() {
if (login) return; if (login) return;
return <> return (
<>
<AsyncButton type="button" className="btn btn-border" onClick={doLogin}> <AsyncButton type="button" className="btn btn-border" onClick={doLogin}>
Login Login
<Icon name="login" /> <Icon name="login" />
</AsyncButton> </AsyncButton>
</> </>
);
} }
return <> function goToStream(ev: NostrEvent) {
const addr = {
pubkey: ev.pubkey,
kind: ev.kind,
identifier: ev.tags.find(t => t.at(0) === "d")?.at(1) || "",
}
const naddr = nip19.naddrEncode(addr)
navigate(`/live/${naddr}`);
setNewStream(false)
}
return (
<>
<header> <header>
<div onClick={() => navigate("/")}> <div onClick={() => navigate("/")}>S</div>
S
</div>
<div className="input"> <div className="input">
<input type="text" placeholder="Search" /> <input type="text" placeholder="Search" />
<Icon name="search" size={15} /> <Icon name="search" size={15} />
@ -62,8 +84,11 @@ export function LayoutPage() {
</div> </div>
</header> </header>
<Outlet /> <Outlet />
{newStream && <Modal onClose={() => setNewStream(false)} > {newStream && (
<NewStream onFinish={() => navigate("/")} /> <Modal onClose={() => setNewStream(false)}>
</Modal>} <NewStream onFinish={goToStream} />
</Modal>
)}
</> </>
);
} }

View File

@ -1646,6 +1646,13 @@
dependencies: dependencies:
eslint-scope "5.1.1" eslint-scope "5.1.1"
"@noble/curves@1.0.0", "@noble/curves@~1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.0.0.tgz#e40be8c7daf088aaf291887cbc73f43464a92932"
integrity sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==
dependencies:
"@noble/hashes" "1.3.0"
"@noble/curves@^1.0.0", "@noble/curves@^1.1.0": "@noble/curves@^1.0.0", "@noble/curves@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d" resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
@ -1653,7 +1660,12 @@
dependencies: dependencies:
"@noble/hashes" "1.3.1" "@noble/hashes" "1.3.1"
"@noble/hashes@1.3.1", "@noble/hashes@^1.3.1": "@noble/hashes@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1"
integrity sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==
"@noble/hashes@1.3.1", "@noble/hashes@^1.3.1", "@noble/hashes@~1.3.0":
version "1.3.1" version "1.3.1"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA== integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
@ -1741,11 +1753,28 @@
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.3.2.tgz#31b9c510d8cada9683549e1dbb4284cca5001faf" resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.3.2.tgz#31b9c510d8cada9683549e1dbb4284cca5001faf"
integrity sha512-V+MvGwaHH03hYhY+k6Ef/xKd6RYlc4q8WBx+2ANmipHJcKuktNcI/NgEsJgdSUF6Lw32njT6OnrRsKYCdgHjYw== integrity sha512-V+MvGwaHH03hYhY+k6Ef/xKd6RYlc4q8WBx+2ANmipHJcKuktNcI/NgEsJgdSUF6Lw32njT6OnrRsKYCdgHjYw==
"@scure/base@1.1.1", "@scure/base@^1.1.1": "@scure/base@1.1.1", "@scure/base@^1.1.1", "@scure/base@~1.1.0":
version "1.1.1" version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938" resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA== integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
"@scure/bip32@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.0.tgz#6c8d980ef3f290987736acd0ee2e0f0d50068d87"
integrity sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==
dependencies:
"@noble/curves" "~1.0.0"
"@noble/hashes" "~1.3.0"
"@scure/base" "~1.1.0"
"@scure/bip39@1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.0.tgz#a207e2ef96de354de7d0002292ba1503538fc77b"
integrity sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==
dependencies:
"@noble/hashes" "~1.3.0"
"@scure/base" "~1.1.0"
"@sinclair/typebox@^0.24.1": "@sinclair/typebox@^0.24.1":
version "0.24.51" version "0.24.51"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f"
@ -6644,6 +6673,17 @@ normalize-url@^6.0.1:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a" resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a"
integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==
nostr-tools@^1.12.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.12.0.tgz#ec3618fc2298e029941b7db3bbe95187777c488f"
integrity sha512-fsIXaNJPKaSrO9MxsCEWbhI4tG4pToQK4D4sgLRD0fRDfZ6ocCg8CLlh9lcNx0o8pVErCMLVASxbJ+w4WNK0MA==
dependencies:
"@noble/curves" "1.0.0"
"@noble/hashes" "1.3.0"
"@scure/base" "1.1.1"
"@scure/bip32" "1.3.0"
"@scure/bip39" "1.2.0"
npm-run-path@^4.0.1: npm-run-path@^4.0.1:
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"