change satellite api

This commit is contained in:
hzrd149 2024-03-27 12:33:19 -05:00
parent 3b34d6b833
commit da2a72a765
3 changed files with 16 additions and 13 deletions

View File

@ -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");

View File

@ -1,5 +1,6 @@
interface Window {
satellite?: {
localRelay?: string;
getLocalRelay: () => Promise<string>;
getAdminAuth: () => Promise<string>;
};
}

View File

@ -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>
);