Skip to content

feat: Waku API's subscribe - #2683

Closed
fryorcraken wants to merge 2 commits into
masterfrom
payload-first-no-filter-change
Closed

fryorcraken wants to merge 2 commits into
masterfrom
payload-first-no-filter-change

Conversation

@fryorcraken

Copy link
Copy Markdown
Collaborator

Introduced a new subscribe function to the Waku API.

Problem / Description

Developer need a simple API to receive messages.

Solution

See TODOs / Notes

API

interface IMessageEmitterEvents {
  [contentTopic: string]: CustomEvent<Uint8Array>;
}

interface IWaku {
	messageEmitter: TypedEventEmitter<IMessageEmitterEvents>;
	subscribe(contentTopics: ContentTopic[]): void;
}

Usage

const contentTopic = "/some/0/content-topic/proto"

// Setup event listener for messages
waku.messageEmitter.addEventListener(contentTopic, (event) => {
	const payload:UInt8Array = event.detail;
	// process payload
  });
});

// Setup event listener for errors
waku.events.addEventListener("error:subscribe", (event) => {
	console.log("internal error:", event.detail);
  });
});

// trigger node subscription
waku.subscribe([contentTopic]);

TODOs / Notes

Specs: logos-messaging/specs#86

  • Remove callback in favour of event emission
  • Demonstrate integration with encryption
  • Demonstrate integration with encryption and reliable channels

Related to #2216


Checklist

  • Code changes are covered by unit tests.
  • Code changes are covered by e2e tests, if applicable.
  • Dogfooding has been performed, if feasible.
  • A test version has been published, if required.
  • All CI checks pass successfully.

Introduced a new `subscribe` function to the Waku API.
@fryorcraken fryorcraken mentioned this pull request Oct 13, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant