mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-11 13:20:37 +02:00
change satellite api
This commit is contained in:
parent
3b34d6b833
commit
da2a72a765
@ -34,7 +34,7 @@ export const localDatabase = await openDB();
|
||||
function createInternalRelay() {
|
||||
return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
||||
}
|
||||
function createRelay() {
|
||||
async function createRelay() {
|
||||
const localRelayURL = localStorage.getItem("localRelay");
|
||||
|
||||
if (localRelayURL) {
|
||||
@ -43,8 +43,8 @@ function createRelay() {
|
||||
} else if (safeRelayUrl(localRelayURL)) {
|
||||
return new Relay(safeRelayUrl(localRelayURL)!);
|
||||
}
|
||||
} else if (window.satellite?.localRelay) {
|
||||
return new Relay(window.satellite?.localRelay);
|
||||
} else if (window.satellite) {
|
||||
return new Relay(await window.satellite.getLocalRelay());
|
||||
} else if (window.CACHE_RELAY_ENABLED) {
|
||||
const protocol = location.protocol === "https:" ? "wss:" : "ws:";
|
||||
return new Relay(new URL(protocol + location.host + "/local-relay").toString());
|
||||
@ -53,7 +53,7 @@ function createRelay() {
|
||||
}
|
||||
|
||||
async function connectRelay() {
|
||||
const relay = createRelay();
|
||||
const relay = await createRelay();
|
||||
try {
|
||||
await relay.connect();
|
||||
log("Connected");
|
||||
|
3
src/types/satellite.d.ts
vendored
3
src/types/satellite.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
interface Window {
|
||||
satellite?: {
|
||||
localRelay?: string;
|
||||
getLocalRelay: () => Promise<string>;
|
||||
getAdminAuth: () => Promise<string>;
|
||||
};
|
||||
}
|
||||
|
18
src/views/relays/cache/index.tsx
vendored
18
src/views/relays/cache/index.tsx
vendored
@ -69,11 +69,13 @@ function NostrRelayTray() {
|
||||
);
|
||||
}
|
||||
function SatelliteRelay() {
|
||||
const relay = window.satellite!.localRelay!;
|
||||
const enabled = localRelay.url === relay;
|
||||
const { value: relay } = useAsync(() => window.satellite!.getLocalRelay());
|
||||
const { value: enabled } = useAsync(async () => localRelay.url === relay, [localRelay.url, relay]);
|
||||
const enable = () => {
|
||||
localStorage.setItem("localRelay", relay);
|
||||
location.reload();
|
||||
if (relay) {
|
||||
localStorage.setItem("localRelay", relay);
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@ -85,9 +87,9 @@ function SatelliteRelay() {
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardBody p="4" pt="0">
|
||||
<Text mb="2">Your installation of noStrudel is setup with a local relay that can be used as a cache</Text>
|
||||
<Text>Maximum capacity: Unknown</Text>
|
||||
<Text>Performance: Unknown, but probably fast...</Text>
|
||||
<Text mb="2">Satellite desktop exposes a local caching relay that can be used to store you events</Text>
|
||||
<Text>Maximum capacity: Unlimited</Text>
|
||||
<Text>Performance: As fast as your computer</Text>
|
||||
</CardBody>
|
||||
</Card>
|
||||
);
|
||||
@ -129,7 +131,7 @@ export default function CacheRelayView() {
|
||||
</Text>
|
||||
<InternalRelay />
|
||||
<NostrRelayTray />
|
||||
{window.satellite?.localRelay && <SatelliteRelay />}
|
||||
{window.satellite && <SatelliteRelay />}
|
||||
{window.CACHE_RELAY_ENABLED && <HostedRelay />}
|
||||
</Flex>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user