Skip to content

Conversation

@avlo
Copy link
Owner

@avlo avlo commented Sep 10, 2024

hi, eric. i'm using this PR (submitted exclusively against my fork of nostr-relay) as an convenient way to discuss an alternative nostr.api.Nostr (client) implementation. given nostr.api.Nostr complexity/nuance to use and since neither the client API nor tests include an easy way to accommodate relay responses, perhaps you might be interested to see a small/simple/useful client implementation leveraging springframework WebSocketClient atop webflux/reactive-streams, composed of 4 parts:

implementation:

  1. dependencies added to nostr-java-api pom.xml:

springframework dependencies:

spring-websocket
spring-webflux

and reactor dependency:

reactor-netty-http
  1. small/simple WebSocketClient reference implementation, in files:
nostr-java-client/src/main/java/nostr/client/springwebsocket/SpringWebSocketClient.java
nostr-java-client/src/main/java/nostr/client/springwebsocket/WebSocketClient.java
nostr-java-client/src/main/java/nostr/client/springwebsocket/WebSocketHandler.java
  1. minimal changes to current codebase for spring websocketclient integration
- class Nostr public method signatures cloned into interface NostrIF
- class Nostr now implements NostrIF
- added class NostrSpringWebSocketClient (SpringWebSocketClient instances reside here) implements NostrIF
  1. class EventNostr formerly:
public abstract class EventNostr<T extends GenericEvent> extends Nostr

updated to:

public abstract class EventNostr<T extends GenericEvent> extends NostrSpringWebSocketClient

with all remaining nostr-java classes/heirarchiess/calls/etc unchanged.

testing:

  1. ApiEventTest methods that send events to relay have been supplemented with callback logic, i.e.,:
await().until(() -> Objects.nonNull(nip01.getRelayResponse()));
nip01.close();

again, this PR isn't intended for approval but rather a convenient way to demonstrate minimal code updates for an alternate (and modern) websocketclient + reactive-stream implementation, should you find value/usefulness/etc in it.

avlo added 29 commits June 14, 2024 09:14
…Factory

added required arrayNode item "subscriptionId" to EventMessage encoder
fixed CanonicalAuthenticationMessage decoder
…ance to use and since the client API doesn't directly support relay responses, i've added a small/simple/useful client implementation leveraging springframework WebSocketClient atop reactive-streams, composed of 4 parts:

implementation:
	1) dependencies added to nostr-java-api pom.xml:

	springframework dependencies:
		spring-websocket
		spring-webflux
	and reactor dependency:
		reactor-netty-http

	2) small/simple WebSocketClient reference implementation, in files:

		nostr-java-client/src/main/java/nostr/client/springwebsocket/SpringWebSocketClient.java
		nostr-java-client/src/main/java/nostr/client/springwebsocket/WebSocketClient.java
		nostr-java-client/src/main/java/nostr/client/springwebsocket/WebSocketHandler.java

	3) minimal/tiny changes to current codebase for spring websocketclient integration
		- class Nostr public method signatures cloned into interface NostrIF
		- class Nostr now implements NostrIF
		- added class NostrSpringWebSocketClient, also implements NostrIF  (this class wraps Spring WebSocketClient reference implementation mentioned above)

	4) class EventNostr formerly:
		public abstract class EventNostr<T extends GenericEvent> extends Nostr
			now
		public abstract class EventNostr<T extends GenericEvent> extends NostrSpringWebSocketClient

	all remaining nostr-java classes/heirarchiess/calls/etc remain unchanged

testing:
	2) ApiEventTest methods that send events to relay have been supplemented with callback logic, i.e.,:

			await().until(() -> Objects.nonNull(nip01.getRelayResponse()));
			nip01.close();
…viously returned <T extends GenericEvent>)

- Nostr send() methods should (and now do) return List<String> (previously returned void)
- NostrIF send() method signatures should (and now do) return List<String> (previously returned void)
- introduced two (per developer's need/choice) web socket clients:
	ReactiveWebSocketClient
	SpringWebSocketClient
- added ClassifiedListingEvent mapping logic for it's contained ClassifiedListing
- added addStandardTag() mapping methods to GenericEvent
- added constructor GenericEventDecoder(Class<T> clazz) to GenericEventDecoder
- updated unit tests per above changes
@avlo avlo closed this Sep 26, 2024
@avlo avlo deleted the spring_websocketclient branch September 26, 2024 23:51
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.

2 participants