Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Are Realtime Updates/WebSockets Available? #93

Open
adam-hurwitz opened this issue Nov 7, 2019 · 3 comments
Open

Are Realtime Updates/WebSockets Available? #93

adam-hurwitz opened this issue Nov 7, 2019 · 3 comments

Comments

@adam-hurwitz
Copy link

adam-hurwitz commented Nov 7, 2019

Question

  • Is there a way to consume the DAPI Client API similar to a WebSocket with realtime updates? @KamuelaFranco mentioned WebSockets are the primary implementation in issue [EV-1204] WebSocket connections #21 .
  • If so, is there an example of a sample pattern to implement in Javascript, Java/Kotlin, etc?

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")
    }
}
@adam-hurwitz adam-hurwitz changed the title Is WebSocket Style Consumption Possible? Are Realtime Updates/WebSockets Available? Nov 7, 2019
@shumkov
Copy link
Member

shumkov commented Nov 7, 2019

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:

  • Add server streaming gRPC endpoint: subscribeToDocuments.
  • Keep filters from consumers in memory. It might be event full-featured queries like fetchDocuments accepts.
  • In block execution process on transaction commit asynchronously test new documents against the filters and send them through the endpoint if a document is following to query filter.

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

@adam-hurwitz
Copy link
Author

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
Copy link
Member

shumkov commented Nov 8, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants