arj03 / ssb-browser-demo

A secure scuttlebutt client interface running in the browser
Other
58 stars 11 forks source link

Fix SSB.connected #38

Closed arj03 closed 3 years ago

arj03 commented 3 years ago

That actually doesn't fix one of the issues I ran into. I initially tried just getting rid of SSB.connected, like you did here:

https://github.com/arj03/ssb-browser-demo/commit/ca194bba462e094cce1093ba9fa6ffac49800f6a#diff-51b24f5be697ccf3d2198c3c57eb757a95ca3c20553f3edf0160af38a5287b5a

But I found that without that, if you clicked "Get msg" before it had actually connected to something (room, pub, etc.), then SSB.net and/or SSB.net.ooo would not exist, and you'd get an exception. Rebuilding SSB.connected like that resulted in it not only not trying to use those before they exist, but also made the request asynchronous. I figured that was how it was originally built to work and seemed like a good way to do it, and it worked very well for me.

Originally posted by @KyleMaas in https://github.com/arj03/ssb-browser-demo/issues/36#issuecomment-760894156

arj03 commented 3 years ago

Yeah, connected was nicer in that way @KyleMaas. It would be nice if the connected would use ssb-conn to figure out when a connection was available, maybe with a timeout.

KyleMaas commented 3 years ago

I just wanted to confirm: SSB.connected() is supposed to register a callback for when any server is connected, correct? And that callback is supposed to be called once and not every time a new connection happens?

arj03 commented 3 years ago

Exactly :)