dashevo / js-dapi-client

DEPRECATED JavaScript client library used to access Dash DAPI endpoints
https://dashevo.github.io/platform/DAPI-Client/
MIT License
10 stars 9 forks source link

Are Realtime Updates/WebSockets Available? #93

Open adam-hurwitz opened 4 years ago

adam-hurwitz commented 4 years ago

Question

WebSockets are now the primary connection mechanism. HTTP requests are a default fallback in the event of socket communication failure.

An example of this is a client that needs to listen for a specific document to be updated from the fetchDocuments call.

Use Case

  1. A user has two apps, Dash Wallet for holding Dash, and a Dash Feature app that uses Dash for an awesome feature. Using Dash Feature requires Dash, and securely initiating a transaction.
  2. In order to create a seamless experience the Dash Feature app adds a request to DAPI for the given user.
  3. DashWallet has a WebSocket call to fetchDocuments listening for any inbound requests. Once a request is received they can verify/decline (similar to Venmo in the U.S.), using existing Dash Wallet authentication.
  4. Dash Feature has it's own WebSocket in order to listen for the completion of the transaction, and carries out the intended feature.

Example from Firebase's Firestore Database

Firebase's Firestore client libraries implement this pattern as outlined in Get realtime updates with Cloud Firestore.

val docRef = db.collection("cities").document("SF")
docRef.addSnapshotListener { snapshot, e ->
    if (e != null) {
        Log.w(TAG, "Listen failed.", e)
        return@addSnapshotListener
    }

    if (snapshot != null && snapshot.exists()) {
        Log.d(TAG, "Current data: ${snapshot.data}")
    } else {
        Log.d(TAG, "Current data: null")
    }
}
shumkov commented 4 years ago

Hello Adam!

It's not implemented yet but we are definitely planning to do that later.

Of course, you can make a PR πŸ˜‰. We always welcome contributions.

It doesn't look like a big deal. It requires some updates in Drive:

We have a similar mechanism in DAPI SPV endpoints (subscribeToTransactionsWithProofs) but much more complicated.

adam-hurwitz commented 4 years ago

Hey Ivan, πŸ‘‹

I appreciate the invite to contribute to the code! If my co-founder and I use DAPI our next feature we'll be exploring this further and would love to add value to the codebase.

shumkov commented 4 years ago

Sounds good! Don't hesitate to ask and share your ideas.