mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-02 12:53:08 +00:00
Merge pull request #269 from waku-org/chore/use-base-multicodec
chore: use `BaseProtocol.multicodec` instead of exported codec
This commit is contained in:
commit
7c24ffa3bf
@ -3,7 +3,6 @@ import { generate } from "server-name-generator";
|
|||||||
import { Message } from "./Message";
|
import { Message } from "./Message";
|
||||||
import { EPeersByDiscoveryEvents, LightNode, Tags } from "@waku/interfaces";
|
import { EPeersByDiscoveryEvents, LightNode, Tags } from "@waku/interfaces";
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import { waku } from "@waku/sdk";
|
|
||||||
|
|
||||||
import { useFilterMessages, useStoreMessages } from "@waku/react";
|
import { useFilterMessages, useStoreMessages } from "@waku/react";
|
||||||
import type {
|
import type {
|
||||||
@ -13,6 +12,7 @@ import type {
|
|||||||
UsePeersResults,
|
UsePeersResults,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { OrderedSet } from "./ordered_array";
|
import { OrderedSet } from "./ordered_array";
|
||||||
|
import { getPeerIdsForProtocol } from "./utils";
|
||||||
|
|
||||||
export const usePersistentNick = (): [
|
export const usePersistentNick = (): [
|
||||||
string,
|
string,
|
||||||
@ -195,18 +195,9 @@ export const usePeers = (params: UsePeersParams): UsePeersResults => {
|
|||||||
|
|
||||||
setPeers({
|
setPeers({
|
||||||
allConnected: peers.map((p) => p.id),
|
allConnected: peers.map((p) => p.id),
|
||||||
storePeers: peers
|
storePeers: getPeerIdsForProtocol(node.store, peers),
|
||||||
.filter((p) => p.protocols.includes(waku.waku_store.StoreCodec))
|
filterPeers: getPeerIdsForProtocol(node.filter, peers),
|
||||||
.map((p) => p.id),
|
lightPushPeers: getPeerIdsForProtocol(node.lightPush, peers),
|
||||||
//TODO: use from import
|
|
||||||
filterPeers: peers
|
|
||||||
.filter((p) =>
|
|
||||||
p.protocols.includes("/vac/waku/filter-subscribe/2.0.0-beta1")
|
|
||||||
)
|
|
||||||
.map((p) => p.id), // hardcoding codec since we don't export it currently
|
|
||||||
lightPushPeers: peers
|
|
||||||
.filter((p) => p.protocols.includes(waku.waku_store.StoreCodec))
|
|
||||||
.map((p) => p.id),
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { Peer } from "@libp2p/interface-peer-store";
|
import type { Peer } from "@libp2p/interface-peer-store";
|
||||||
|
import type { IFilter, ILightPush, IStore } from "@waku/interfaces";
|
||||||
|
|
||||||
export async function handleCatch(
|
export async function handleCatch(
|
||||||
promise?: Promise<Peer[]>
|
promise?: Promise<Peer[]>
|
||||||
@ -13,3 +14,14 @@ export async function handleCatch(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPeerIdsForProtocol(
|
||||||
|
protocol: IStore | ILightPush | IFilter | undefined,
|
||||||
|
peers: Peer[]
|
||||||
|
) {
|
||||||
|
return protocol
|
||||||
|
? peers
|
||||||
|
.filter((p) => p.protocols.includes(protocol.multicodec))
|
||||||
|
.map((p) => p.id)
|
||||||
|
: [];
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user