mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
Merge 1361cf57e1139c44f0d9aa427e79c10fccbfdb20 into f2ad23ad4354fb3440ca369ed91ba4d882bbacf6
This commit is contained in:
commit
f130857d4a
@ -1,5 +1,4 @@
|
||||
import type { PeerId } from "@libp2p/interface";
|
||||
import type { IncomingStreamData } from "@libp2p/interface-internal";
|
||||
import type { PeerId, StreamHandler } from "@libp2p/interface";
|
||||
import {
|
||||
type ContentTopic,
|
||||
type FilterCoreResult,
|
||||
@ -52,7 +51,7 @@ export class FilterCore {
|
||||
|
||||
public async start(): Promise<void> {
|
||||
try {
|
||||
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
||||
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest, {
|
||||
maxInboundStreams: 100
|
||||
});
|
||||
} catch (e) {
|
||||
@ -305,7 +304,7 @@ export class FilterCore {
|
||||
};
|
||||
}
|
||||
|
||||
private onRequest(streamData: IncomingStreamData): void {
|
||||
private onRequest: StreamHandler = (streamData) => {
|
||||
const { connection, stream } = streamData;
|
||||
const { remotePeer } = connection;
|
||||
log.info(`Received message from ${remotePeer.toString()}`);
|
||||
@ -346,5 +345,5 @@ export class FilterCore {
|
||||
} catch (e) {
|
||||
log.error("Error decoding message", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ describe("StreamManager", () => {
|
||||
createMockStream({ id: "1", protocol: MULTICODEC, writeStatus })
|
||||
];
|
||||
|
||||
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
|
||||
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
|
||||
_peerId: PeerId | undefined
|
||||
) => [con1];
|
||||
|
||||
@ -50,7 +50,7 @@ describe("StreamManager", () => {
|
||||
});
|
||||
|
||||
it("should return undefined if no connection provided", async () => {
|
||||
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
|
||||
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
|
||||
_peerId: PeerId | undefined
|
||||
) => [];
|
||||
|
||||
@ -74,7 +74,7 @@ describe("StreamManager", () => {
|
||||
);
|
||||
|
||||
con1.newStream = newStreamSpy;
|
||||
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
|
||||
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
|
||||
_peerId: PeerId | undefined
|
||||
) => [con1];
|
||||
|
||||
@ -101,7 +101,7 @@ describe("StreamManager", () => {
|
||||
);
|
||||
|
||||
con1.newStream = newStreamSpy;
|
||||
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
|
||||
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
|
||||
_peerId: PeerId | undefined
|
||||
) => [con1];
|
||||
|
||||
@ -152,7 +152,7 @@ describe("StreamManager", () => {
|
||||
writeStatus: "writable"
|
||||
})
|
||||
];
|
||||
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
|
||||
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
|
||||
_id: PeerId | undefined
|
||||
) => [con1];
|
||||
|
||||
@ -182,7 +182,6 @@ function createMockConnection(options: MockConnectionOptions = {}): Connection {
|
||||
}
|
||||
} as Connection;
|
||||
}
|
||||
|
||||
type MockStreamOptions = {
|
||||
id?: string;
|
||||
protocol?: string;
|
||||
|
||||
@ -25,10 +25,12 @@ export type CreateEncoderParams = CreateDecoderParams & {
|
||||
ephemeral?: boolean;
|
||||
};
|
||||
|
||||
export enum WakuEvent {
|
||||
Connection = "waku:connection",
|
||||
Health = "waku:health"
|
||||
}
|
||||
export const WakuEvent = {
|
||||
Connection: "waku:connection",
|
||||
Health: "waku:health"
|
||||
} as const;
|
||||
|
||||
export type WakuEvent = (typeof WakuEvent)[keyof typeof WakuEvent];
|
||||
|
||||
export interface IWakuEvents {
|
||||
/**
|
||||
@ -36,22 +38,22 @@ export interface IWakuEvents {
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* waku.addEventListener(WakuEvent.Connection, (event) => {
|
||||
* waku.events.addEventListener("waku:connection", (event) => {
|
||||
* console.log(event.detail); // true if connected, false if disconnected
|
||||
* });
|
||||
*/
|
||||
[WakuEvent.Connection]: CustomEvent<boolean>;
|
||||
"waku:connection": CustomEvent<boolean>;
|
||||
|
||||
/**
|
||||
* Emitted when the health status changes.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* waku.addEventListener(WakuEvent.Health, (event) => {
|
||||
* waku.events.addEventListener("waku:health", (event) => {
|
||||
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
|
||||
* });
|
||||
*/
|
||||
[WakuEvent.Health]: CustomEvent<HealthStatus>;
|
||||
"waku:health": CustomEvent<HealthStatus>;
|
||||
}
|
||||
|
||||
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
|
||||
@ -66,12 +68,12 @@ export interface IWaku {
|
||||
/**
|
||||
* Emits events related to the Waku node.
|
||||
* Those are:
|
||||
* - WakuEvent.Connection
|
||||
* - WakuEvent.Health
|
||||
* - "waku:connection"
|
||||
* - "waku:health"
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* waku.events.addEventListener(WakuEvent.Connection, (event) => {
|
||||
* waku.events.addEventListener("waku:connection", (event) => {
|
||||
* console.log(event.detail); // true if connected, false if disconnected
|
||||
* });
|
||||
* ```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user