getAlby / js-sdk

JavaScript SDK for the Alby OAuth2 Wallet API and the Nostr Wallet Connect API.
https://npmjs.com/package/@getalby/sdk
63 stars 16 forks source link

NostrWeblnProvider does not reconnect if the connection is lost #154

Closed bumi closed 9 months ago

bumi commented 10 months ago

Currently it seems that the NostrWeblnProvider is not reconnecting to the relay if the connection is lost and then the checkConnected function throws an error.

Maybe we shoud auto-connect in the checkConnected function if the connection is not open?

Then the question is if we need an additional enabled state to only do this when .enable() was called before.

rolznz commented 10 months ago

nostr-tools now does this, but it's not published yet: https://github.com/nbd-wtf/nostr-tools/blob/HEAD/relay.ts

rolznz commented 10 months ago

I made an example to test this locally where you can do:

This already works unless I switch WIFI networks.

I checked if I can get any error message, but relay.on("disconnect") and relay.on("error") never fires, and the underlying ws object is not exposed to the Relay, so we cannot access it directly. The status function always returns 1 even if the internet is disconnected, and the current version of nostr-tools always checks the ws readyState (which is always 1) so the reconnect logic never gets called :confused:

I think steps should be:

rolznz commented 9 months ago

I was wrong. Fixed by https://github.com/getAlby/js-sdk/pull/172