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