mirror of https://github.com/waku-org/js-waku.git
feat!: use ISender and deprecate Light Push .push (#1217)
This commit is contained in:
parent
b8f7db21c7
commit
0f6a594644
|
@ -36,7 +36,7 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|||
this.options = options || {};
|
||||
}
|
||||
|
||||
async push(
|
||||
async send(
|
||||
encoder: IEncoder,
|
||||
message: IMessage,
|
||||
opts?: ProtocolOptions
|
||||
|
|
|
@ -8,3 +8,4 @@ export * from "./relay.js";
|
|||
export * from "./store.js";
|
||||
export * from "./waku.js";
|
||||
export * from "./connection_manager.js";
|
||||
export * from "./sender.js";
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
import type { IEncoder, IMessage } from "./message.js";
|
||||
import type {
|
||||
PointToPointProtocol,
|
||||
ProtocolOptions,
|
||||
SendResult,
|
||||
} from "./protocols.js";
|
||||
import type { PointToPointProtocol } from "./protocols.js";
|
||||
import type { ISender } from "./sender.js";
|
||||
|
||||
export interface ILightPush extends PointToPointProtocol {
|
||||
push: (
|
||||
encoder: IEncoder,
|
||||
message: IMessage,
|
||||
opts?: ProtocolOptions
|
||||
) => Promise<SendResult>;
|
||||
}
|
||||
export type ILightPush = ISender & PointToPointProtocol;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import type { GossipSub, GossipsubEvents } from "@chainsafe/libp2p-gossipsub";
|
||||
import type { EventEmitter } from "@libp2p/interfaces/events";
|
||||
|
||||
import type {
|
||||
IDecodedMessage,
|
||||
IDecoder,
|
||||
IEncoder,
|
||||
IMessage,
|
||||
} from "./message.js";
|
||||
import type { Callback, SendResult } from "./protocols.js";
|
||||
import type { IDecodedMessage, IDecoder } from "./message.js";
|
||||
import type { Callback } from "./protocols.js";
|
||||
import type { ISender } from "./sender.js";
|
||||
|
||||
export interface RelayEvents {
|
||||
"observer:added": CustomEvent;
|
||||
|
@ -16,8 +12,7 @@ export interface RelayEvents {
|
|||
|
||||
type IRelayEmitter = EventEmitter<RelayEvents & GossipsubEvents>;
|
||||
|
||||
interface IRelayAPI extends GossipSub {
|
||||
send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
|
||||
interface IRelayAPI {
|
||||
addObserver: <T extends IDecodedMessage>(
|
||||
decoder: IDecoder<T>,
|
||||
callback: Callback<T>
|
||||
|
@ -25,4 +20,4 @@ interface IRelayAPI extends GossipSub {
|
|||
getMeshPeers: () => string[];
|
||||
}
|
||||
|
||||
export type IRelay = IRelayAPI & IRelayEmitter;
|
||||
export type IRelay = ISender & GossipSub & IRelayAPI & IRelayEmitter;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import type { IEncoder, IMessage } from "./message.js";
|
||||
import type { ProtocolOptions, SendResult } from "./protocols.js";
|
||||
|
||||
export interface ISender {
|
||||
send: (
|
||||
encoder: IEncoder,
|
||||
message: IMessage,
|
||||
opts?: ProtocolOptions
|
||||
) => Promise<SendResult>;
|
||||
}
|
|
@ -135,9 +135,9 @@ describe("Waku Message Ephemeral field", () => {
|
|||
|
||||
log("Sending messages using light push");
|
||||
await Promise.all([
|
||||
waku1.lightPush.push(asymEncoder, asymMsg),
|
||||
waku1.lightPush.push(symEncoder, symMsg),
|
||||
waku1.lightPush.push(clearEncoder, clearMsg),
|
||||
waku1.lightPush.send(asymEncoder, asymMsg),
|
||||
waku1.lightPush.send(symEncoder, symMsg),
|
||||
waku1.lightPush.send(clearEncoder, clearMsg),
|
||||
]);
|
||||
|
||||
await waitForRemotePeer(waku2, [Protocols.Store]);
|
||||
|
@ -181,10 +181,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||
await delay(200);
|
||||
const normalTxt = "Normal message";
|
||||
const ephemeralTxt = "Ephemeral Message";
|
||||
await waku.lightPush.push(TestEncoder, {
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes(normalTxt),
|
||||
});
|
||||
await waku.lightPush.push(ephemeralEncoder, {
|
||||
await waku.lightPush.send(ephemeralEncoder, {
|
||||
payload: utf8ToBytes(ephemeralTxt),
|
||||
});
|
||||
while (messages.length < 2) {
|
||||
|
@ -230,10 +230,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||
await delay(200);
|
||||
const normalTxt = "Normal message";
|
||||
const ephemeralTxt = "Ephemeral Message";
|
||||
await waku.lightPush.push(encoder, {
|
||||
await waku.lightPush.send(encoder, {
|
||||
payload: utf8ToBytes(normalTxt),
|
||||
});
|
||||
await waku.lightPush.push(ephemeralEncoder, {
|
||||
await waku.lightPush.send(ephemeralEncoder, {
|
||||
payload: utf8ToBytes(ephemeralTxt),
|
||||
});
|
||||
while (messages.length < 2) {
|
||||
|
@ -280,10 +280,10 @@ describe("Waku Message Ephemeral field", () => {
|
|||
await delay(200);
|
||||
const normalTxt = "Normal message";
|
||||
const ephemeralTxt = "Ephemeral Message";
|
||||
await waku.lightPush.push(encoder, {
|
||||
await waku.lightPush.send(encoder, {
|
||||
payload: utf8ToBytes(normalTxt),
|
||||
});
|
||||
await waku.lightPush.push(ephemeralEncoder, {
|
||||
await waku.lightPush.send(ephemeralEncoder, {
|
||||
payload: utf8ToBytes(ephemeralTxt),
|
||||
});
|
||||
while (messages.length < 2) {
|
||||
|
|
|
@ -63,7 +63,7 @@ describe("Waku Filter", () => {
|
|||
// correct in future versions of the protocol.
|
||||
await delay(200);
|
||||
|
||||
await waku.lightPush.push(TestEncoder, message);
|
||||
await waku.lightPush.send(TestEncoder, message);
|
||||
while (messageCount === 0) {
|
||||
await delay(250);
|
||||
}
|
||||
|
@ -81,10 +81,10 @@ describe("Waku Filter", () => {
|
|||
await waku.filter.subscribe([TestDecoder], callback);
|
||||
|
||||
await delay(200);
|
||||
await waku.lightPush.push(TestEncoder, {
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("Filtering works!"),
|
||||
});
|
||||
await waku.lightPush.push(TestEncoder, {
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("Filtering still works!"),
|
||||
});
|
||||
while (messageCount < 2) {
|
||||
|
@ -101,13 +101,13 @@ describe("Waku Filter", () => {
|
|||
const unsubscribe = await waku.filter.subscribe([TestDecoder], callback);
|
||||
|
||||
await delay(200);
|
||||
await waku.lightPush.push(TestEncoder, {
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("This should be received"),
|
||||
});
|
||||
await delay(100);
|
||||
await unsubscribe();
|
||||
await delay(200);
|
||||
await waku.lightPush.push(TestEncoder, {
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("This should not be received"),
|
||||
});
|
||||
await delay(100);
|
||||
|
|
|
@ -46,7 +46,7 @@ describe("Waku Light Push [node only]", () => {
|
|||
|
||||
const messageText = "Light Push works!";
|
||||
|
||||
const pushResponse = await waku.lightPush.push(TestEncoder, {
|
||||
const pushResponse = await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes(messageText),
|
||||
});
|
||||
expect(pushResponse.recipients.length).to.eq(1);
|
||||
|
@ -87,7 +87,7 @@ describe("Waku Light Push [node only]", () => {
|
|||
const messageText = "Light Push works!";
|
||||
|
||||
log("Send message via lightpush");
|
||||
const pushResponse = await waku.lightPush.push(
|
||||
const pushResponse = await waku.lightPush.send(
|
||||
TestEncoder,
|
||||
{ payload: utf8ToBytes(messageText) },
|
||||
{
|
||||
|
|
|
@ -412,10 +412,10 @@ describe("Waku Store", () => {
|
|||
|
||||
log("Sending messages using light push");
|
||||
await Promise.all([
|
||||
waku1.lightPush.push(eciesEncoder, asymMsg),
|
||||
waku1.lightPush.push(symEncoder, symMsg),
|
||||
waku1.lightPush.push(otherEncoder, otherMsg),
|
||||
waku1.lightPush.push(TestEncoder, clearMsg),
|
||||
waku1.lightPush.send(eciesEncoder, asymMsg),
|
||||
waku1.lightPush.send(symEncoder, symMsg),
|
||||
waku1.lightPush.send(otherEncoder, otherMsg),
|
||||
waku1.lightPush.send(TestEncoder, clearMsg),
|
||||
]);
|
||||
|
||||
await waitForRemotePeer(waku2, [Protocols.Store]);
|
||||
|
|
Loading…
Reference in New Issue