web5-js
web5-js copied to clipboard
Subscribe api
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?
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.
Code already exists in aggregator. Can easily lift it and drop it into here
@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.
yeah lets
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