LukasPoque / s3i_flutter

A library that makes it easy to communicate with the S³I (Smart Systems Service Infrastructure of the KWH4.0)
https://pub.dev/packages/s3i_flutter
MIT License
4 stars 1 forks source link

Add "live" thing subscription. #6

Open LukasPoque opened 3 years ago

LukasPoque commented 3 years ago

It would be a really nice feature if this package could receive ditto signals, especially to consume changes in "real-time". Ditto provides this feature via WebSockets or HTTP SSE [or over connection with the connectivity service].

This could be very useful for dashboards, maps, and thing observing.

LukasPoque commented 3 years ago

Since this is only the receiving part, we don't need to deal with different local and cloud versions.

The method signature could be something like that:

/// thingId -> the id of the observed thing
/// callbackUpdate -> is triggered if a ditto change event is received. Provides the whole thing with the updated data.
/// callbackError -> is triggered if an error/exception occurred during the subscription
/// rqlFilter -> used to filter only specific events
void startSubscribingLiveThing(String thingId, Function(Thing) callbackUpdate, 
    {Function(Exception) callbackError, RQLQuery? rqlFilter});

void endSubscribingLiveThing(String thingId);

We use the thingId to specify the namespaces-filter option in order to receive only events from this specific thing.

Maybe it`s a good idea to provide the general method too, this could be something like that:

void startSubscribingDittoEvents(Function(String) callbackNewEvent, 
    {Function(Exception) callbackError, RQLQuery? rqlFilter, NamespaceQuery? namespaces});

void endSubscribingDittoEvents();
LukasPoque commented 3 years ago

Maybe we should consider supporting the S3I-EventSystem too.

LukasPoque commented 3 years ago

We should support the new S3I-Event-System! But in my opinion the event system isn't suitable for this kind of live thing mode. It's better to include this in an other way in this package.

There is no public document available at the moment so I can't add the description of the new event system.

LukasPoque commented 3 years ago

See #9 for everything related to the S3I Event System. This issue should be for the "live" thing via ditto only.