WebThingsIO / gateway

WebThings Gateway - a self-hosted web application for monitoring and controlling a building over the web
http://webthings.io/gateway
Mozilla Public License 2.0
2.62k stars 339 forks source link

Catch up on missed events/property changes when an SSE client re-connects #3087

Open benfrancis opened 1 year ago

benfrancis commented 1 year ago

The HTTP SSE Profile provides a mechanism for Consumers to catch up missed events and property changes if a client re-connects after a Server-Sent Events connection drops:

If the connection between the Consumer and Web Thing drops (except as a result of the unobserve operation defined below), the Consumer MUST re-establish the connection following the steps outlined in the Server-Sent Events specification [EVENTSOURCE]. Once the connection is re-established the Web Thing SHOULD, if possible, send any missed property changes which occurred since the last change specified by the Consumer in a Last-Event-ID header.

If the connection between the Consumer and Web Thing drops (except as a result of the unsubscribeevent operation defined below), the Consumer MUST re-establish the connection following the steps outlined in the Server-Sent Events specification [EVENTSOURCE]. Once the connection is re-established the Web Thing SHOULD, if possible, send any missed events which occurred since the last event specified by the Consumer in a Last-Event-ID header.

This would require keeping a cache in memory of events and property readings and sending missed events when a connection is re-established.

There would need to be an upper limit on the number of values stored.