The Stream.online event type includes a field “started_at” which gives an exact timestamp of the stream start. The Stream.offline event does not have a matching field to describe when a stream went offline.
We’re finding it difficult to be entirely sure whether or not a stream is online or offline in cases where events are delivered out of order. If a streamer has a live stream and quickly stops then starts their stream, we sometimes receive the ended offline event last, which would incorrectly suggest the stream is now offline. Adding in the timestamp to the offline event may help to alleviate this scenario.
That would/should be the header Twitch-Eventsub-Message-Timestamp to help track this. (I don’t recall if it changes between retries but I don’t often get retries, but I think suffices for your use case)
Alternatively raise a uservoice requesting a field added to the Payload
I cross reference the API in “critical” applications that need to know for sure.
But I’m yet to have this paticular scenario occur. (events in the wrong order)
Depending on the use case the “fix” I guess would be to poll the API as well.
For my “critical” application I referred to earlier I use Eventsub to get it in real time but I also periodically check the API as well to account for anything in the wrong order.
Thankfully this is rare for the users I operate with.
But you could just add a simple “well I got weird start/stop traffic in a short time I’ll schedule an API sanity check in a few minutes” rather than a continual poll like I do
Looks like the Twitch-Eventsub-Message-Timestamp helps to solve the out of order issue. Was able to trigger the issue by stopping and restarting the stream quickly, and the timestamps still represent a good order despite the events arriving out of order.
We’re also considering a monitor but the /streams endpoint can also return incorrect data for a short time after the stream status has changed in terms of offline/online. This would hopefully reenforce event tracking but I wouldn’t want to overwrite a valid event with an incorrect /streams value.
Could also be beneficial to add an identifier to Stream.online and Stream.online to match them up. This would be more helpful in terms of event retries but is probably a bigger ask than anything else.