@@ -47,7 +47,7 @@ void setup() {
4747 testNIP01Filter ();
4848}
4949
50- void loop () {
50+ void loop () {
5151 for (nostr::NostrPool *pool : pools) {
5252 pool->loop ();
5353 }
@@ -56,28 +56,28 @@ void loop() {
5656nostr::Transport *transport;
5757
5858void testNIP01Filter () {
59- try {
59+ try {
6060 String relay = RELAY;
6161 transport = nostr::esp32::ESP32Platform::getTransport ();
6262 nostr::NostrPool *pool = new nostr::NostrPool (transport);
6363 pools.push_back (pool);
6464 String subId = pool->subscribeMany (
6565 {relay},
6666 {{
67- {" kinds" , {" 1" }},
68- {" since" , {" 1626023056" }},
69- {" until" , {" 1846947856" }},
67+ {" kinds" , {" 1" }},
68+ {" since" , {" 1626023056" }},
69+ {" until" , {" 1846947856" }},
7070 {" limit" , {" 10" }},
7171 // Filters defined in NIP01 are automatically converted to the correct type
72- // however this library support non-NIP01 filters as well, but you might need to
72+ // however this library support non-NIP01 filters as well, but you might need to
7373 // specify their type manually, if unspecified the code assumes string[]:
7474 // eg. {"int newFilter", {"1"}}
7575 // eg. {"int[] newFilter2", {"1", "2"}}
7676 // eg. {"float newFilter3", {"1.1"}}
7777 // eg. {"float[] newFilter4", {"1.1", "2.2"}}
7878 // eg. {"string newFilter5", {"hello"}}
7979 }},
80- [&](const String &subId, nostr::SignedNostrEvent *event) {
80+ [&](const String &subId, nostr::SignedNostrEvent *event) {
8181 JsonDocument doc;
8282 JsonArray arr = doc[" data" ].to <JsonArray>();
8383 event->toSendableEvent (arr);
@@ -86,6 +86,22 @@ void testNIP01Filter() {
8686 Serial.println (" Event received: " + json);
8787 },
8888 [&](const String &subId, const String &reason) { Serial.println (" Subscription closed: " + reason); }, [&](const String &subId) { Serial.println (" Subscription EOSE: " + subId); });
89+
90+ std::vector<nostr::NostrRelay *> *relays = pool->getConnectedRelays ();
91+ for (nostr::NostrRelay *relay : *relays) {
92+ Serial.println (" Registering to connection events of: " + relay->getUrl ());
93+ relay->getConnection ()->addConnectionStatusListener ([&](const nostr::ConnectionStatus &status) {
94+ String sstatus=" UNKNOWN" ;
95+ if (status==nostr::ConnectionStatus::CONNECTED){
96+ sstatus=" CONNECTED" ;
97+ }else if (status==nostr::ConnectionStatus::DISCONNECTED){
98+ sstatus=" DISCONNECTED" ;
99+ }else if (status==nostr::ConnectionStatus::ERROR){
100+ sstatus = " ERROR" ;
101+ }
102+ Serial.println (" Connection status changed: " + sstatus);
103+ });
104+ }
89105 } catch (const std::exception &e) {
90106 Serial.println (" Error: " + String (e.what ()));
91107 }
0 commit comments