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/user-event": "^13.2.1",
"hls.js": "^1.4.6",
"nostr-tools": "^1.12.0",
"qr-code-styling": "^1.6.0-rc.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",

View File

@ -6,7 +6,13 @@ import AsyncButton from "./async-button";
import { System } from "index";
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 [summary, setSummary] = useState(findTag(ev, "summary") ?? "");
const [image, setImage] = useState(findTag(ev, "image") ?? "");
@ -33,66 +39,82 @@ export function NewStream({ ev, onFinish }: { ev?: NostrEvent, onFinish: () => v
async function publishStream() {
const pub = await EventPublisher.nip7();
if (pub) {
const evNew = await pub.generic(eb => {
const evNew = await pub.generic((eb) => {
const now = unixNow();
const dTag = findTag(ev, "d") ?? now.toString();
return eb.kind(30_311)
return eb
.kind(30_311)
.tag(["d", dTag])
.tag(["title", title])
.tag(["summary", summary])
.tag(["image", image])
.tag(["streaming", stream])
.tag(["status", "live"])
.tag(["status", "live"]);
});
console.debug(evNew);
System.BroadcastEvent(evNew);
onFinish();
//System.BroadcastEvent(evNew);
onFinish(evNew);
}
}
return <div className="new-stream">
<h3>
{ev ? "Edit Stream" : "New Stream"}
</h3>
return (
<div className="new-stream">
<h3>{ev ? "Edit Stream" : "New Stream"}</h3>
<div>
<p>
Title
</p>
<p>Title</p>
<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>
<p>
Summary
</p>
<p>Summary</p>
<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>
<p>
Cover image
</p>
<p>Cover image</p>
<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>
<p>
Stream Url
</p>
<p>Stream Url</p>
<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>
<small>
Stream type should be HLS
</small>
<small>Stream type should be HLS</small>
</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"}
</AsyncButton>
</div>
</div>
);
}

View File

@ -1,6 +1,7 @@
import { Icon } from "element/icon";
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 AsyncButton from "element/async-button";
import { Login } from "index";
@ -25,33 +26,54 @@ export function LayoutPage() {
function loggedIn() {
if (!login) return;
return <>
<button type="button" className="btn btn-primary" onClick={() => setNewStream(true)}>
return (
<>
<button
type="button"
className="btn btn-primary"
onClick={() => setNewStream(true)}
>
New Stream
<Icon name="signal" />
</button>
<Profile pubkey={login.pubkey} options={{
showName: false
}} />
<Profile
pubkey={login.pubkey}
options={{
showName: false,
}}
/>
</>
);
}
function loggedOut() {
if (login) return;
return <>
return (
<>
<AsyncButton type="button" className="btn btn-border" onClick={doLogin}>
Login
<Icon name="login" />
</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>
<div onClick={() => navigate("/")}>
S
</div>
<div onClick={() => navigate("/")}>S</div>
<div className="input">
<input type="text" placeholder="Search" />
<Icon name="search" size={15} />
@ -62,8 +84,11 @@ export function LayoutPage() {
</div>
</header>
<Outlet />
{newStream && <Modal onClose={() => setNewStream(false)} >
<NewStream onFinish={() => navigate("/")} />
</Modal>}
{newStream && (
<Modal onClose={() => setNewStream(false)}>
<NewStream onFinish={goToStream} />
</Modal>
)}
</>
);
}

View File

@ -1646,6 +1646,13 @@
dependencies:
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":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
@ -1653,7 +1660,12 @@
dependencies:
"@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"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
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"
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"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
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":
version "0.24.51"
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"
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:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"