Nostr provider tweaks
This commit is contained in:
@ -13,10 +13,14 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
|
|||||||
const [info, setInfo] = useState<StreamProviderInfo>();
|
const [info, setInfo] = useState<StreamProviderInfo>();
|
||||||
const [ep, setEndpoint] = useState<StreamProviderEndpoint>();
|
const [ep, setEndpoint] = useState<StreamProviderEndpoint>();
|
||||||
|
|
||||||
|
function sortEndpoints(arr: Array<StreamProviderEndpoint>) {
|
||||||
|
return arr.sort((a, b) => (a.rate ?? 0) > (b.rate ?? 0) ? -1 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
provider.info().then(v => {
|
provider.info().then(v => {
|
||||||
setInfo(v);
|
setInfo(v);
|
||||||
setEndpoint(v.endpoints[0]);
|
setEndpoint(sortEndpoints(v.endpoints)[0]);
|
||||||
});
|
});
|
||||||
}, [provider]);
|
}, [provider]);
|
||||||
|
|
||||||
@ -51,12 +55,24 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
|
|||||||
return `${raw.toFixed(0)} ${ep.unit} @ ${ep.rate} sats/${ep.unit}`
|
return `${raw.toFixed(0)} ${ep.unit} @ ${ep.rate} sats/${ep.unit}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseCapability(cap: string) {
|
||||||
|
const [tag, ...others] = cap.split(":");
|
||||||
|
if (tag === "variant") {
|
||||||
|
const [height] = others;
|
||||||
|
return height === "source" ? height : `${height.slice(0, -1)}p`;
|
||||||
|
}
|
||||||
|
if (tag === "output") {
|
||||||
|
return others[0];
|
||||||
|
}
|
||||||
|
return cap;
|
||||||
|
}
|
||||||
|
|
||||||
const streamEvent = others.ev ?? info.publishedEvent ?? DummyEvent;
|
const streamEvent = others.ev ?? info.publishedEvent ?? DummyEvent;
|
||||||
return <>
|
return <>
|
||||||
{info.endpoints.length > 1 && <div>
|
{info.endpoints.length > 1 && <div>
|
||||||
<p>Endpoint</p>
|
<p>Endpoint</p>
|
||||||
<div className="flex g12">
|
<div className="flex g12">
|
||||||
{info.endpoints.map(a => <span className={`pill${ep?.name === a.name ? " active" : ""}`}
|
{sortEndpoints(info.endpoints).map(a => <span className={`pill${ep?.name === a.name ? " active" : ""}`}
|
||||||
onClick={() => setEndpoint(a)}>
|
onClick={() => setEndpoint(a)}>
|
||||||
{a.name}
|
{a.name}
|
||||||
</span>)}
|
</span>)}
|
||||||
@ -91,6 +107,12 @@ export function NostrProviderDialog({ provider, ...others }: { provider: StreamP
|
|||||||
</div>
|
</div>
|
||||||
<small>About {calcEstimate()}</small>
|
<small>About {calcEstimate()}</small>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>Resolutions</p>
|
||||||
|
<div className="flex g12">
|
||||||
|
{ep?.capabilities?.map(a => <span className="pill">{parseCapability(a)}</span>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{streamEvent && <StreamEditor onFinish={(ex) => {
|
{streamEvent && <StreamEditor onFinish={(ex) => {
|
||||||
provider.updateStreamInfo(ex);
|
provider.updateStreamInfo(ex);
|
||||||
others.onFinish?.(ex);
|
others.onFinish?.(ex);
|
||||||
|
@ -55,7 +55,9 @@ export interface StreamProviderEndpoint {
|
|||||||
key: string
|
key: string
|
||||||
rate?: number
|
rate?: number
|
||||||
unit?: string
|
unit?: string
|
||||||
|
capabilities?: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ProviderStore extends ExternalStore<Array<StreamProvider>> {
|
export class ProviderStore extends ExternalStore<Array<StreamProvider>> {
|
||||||
#providers: Array<StreamProvider> = []
|
#providers: Array<StreamProvider> = []
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ export class Nip103StreamProvider implements StreamProvider {
|
|||||||
key: a.key,
|
key: a.key,
|
||||||
rate: a.cost.rate,
|
rate: a.cost.rate,
|
||||||
unit: a.cost.unit,
|
unit: a.cost.unit,
|
||||||
|
capabilities: a.capabilities
|
||||||
} as StreamProviderEndpoint
|
} as StreamProviderEndpoint
|
||||||
})
|
})
|
||||||
} as StreamProviderInfo
|
} as StreamProviderInfo
|
||||||
|
Reference in New Issue
Block a user