web5-js icon indicating copy to clipboard operation
web5-js copied to clipboard

Subscribe api

Open michaelneale opened this issue 1 year ago • 5 comments

It would make sense in web5 api to have a subscribe api to "listen" for changes that match a filter for (example) your own DID (eg if you are building a messaging system). is this possible?

michaelneale avatar Mar 08 '23 07:03 michaelneale

Yes, there's no reason we can't introduce a 'live stream' style method to the Records interface, like Web5.records.feed(), that takes a query filter of the same type RecordsQuery already does and establishes a streamed feed of all things that match it. This should be something @mistermoe and @thehenrytsai can weigh in on and add in some form to service the need.

csuwildcat avatar Mar 08 '23 07:03 csuwildcat

Code already exists in aggregator. Can easily lift it and drop it into here

mistermoe avatar Mar 08 '23 08:03 mistermoe

@mistermoe can you, I, @michaelneale, @thehenrytsai, and @frankhinek do a little session to walk through the requirements for a feed feature? I am wondering how it could manifest in a general way for the API surface.

csuwildcat avatar Mar 08 '23 14:03 csuwildcat

yeah lets

michaelneale avatar Mar 08 '23 21:03 michaelneale

we can chat tomorrow - but the basic idea is that if web5-sdk is connecting to a did that is remote (eg an aggregator style DWN) is there a way we can have a callback type of api for a subscriube that matches a certain filter.

Use cases:

real time messaging to remote DWN Dropbox type of thing TBDex Avoiding aggro-polling some remote server if you want to sync it to local unaddressable node

etc

did I capture that @mistermoe?

something like:

const response = await Web5.records.subscribe('did:example:bob', {
  author: 'did:example:alice',
  message: {
    filter: {
      schema: 'https://schema.org/Playlist',
      dataFormat: 'application/json'
    }
  }
}, function(result) {  .... } );

any time we get a new playlist, it calls the callback

michaelneale avatar Mar 09 '23 00:03 michaelneale