From a49c152707a8f002d2e705144e331016313d2c13 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Tue, 13 Aug 2024 18:38:47 -0700 Subject: [PATCH] www: fix short sentry event When there is a new Sentry event detected while the car is still recording video for the previous Sentry events, it can create a 1-minute event whose event time preceeds the recordings for the event. In this case the car's viewer (and, prior to this change, the TeslaUSB web viewer) would not show the event marker on the progress slider. With this change, TeslaUSB will check if the event time from event.json precedes the event recording timestamp, and if so it will add the previous minute's recordings from RecentClips. --- teslausb-www/html/index.html | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/teslausb-www/html/index.html b/teslausb-www/html/index.html index d0d870c5..3e7f0b2c 100755 --- a/teslausb-www/html/index.html +++ b/teslausb-www/html/index.html @@ -2173,11 +2173,40 @@ var s = segment.datetime; eventSegmentStartMs = Date.parse( s.substring(0,10) + "T" + s.substring(11,13) + ":" + s.substring(14,16) + ":" + s.substring(17, 19)); - if (eventSegmentStartMs <= eventTimeMs) { + if (eventSegmentStartMs <= eventTimeMs || segmentIdx == 0) { break; } } var offsetIntoSegment = eventTimeMs - eventSegmentStartMs; + if (offsetIntoSegment < 0) { + /* The event time is before the first video segment. This can + happen if there are two sentry events in short succession */ + log("negative sentry offset"); + if (offsetIntoSegment > -60000) { + /* add one segment to the start of the sequence */ + //return drawTickForIndex(idx); + var segment = this.getSegmentByIndex(0); + var s = segment.datetime.substring(0,10); + var dayclips = videos["RecentClips"][s]; + if (dayclips != undefined) { + var prevseg; + for (var seg of dayclips.segments) { + if (seg.datetime == segment.datetime) { + break; + } + prevseg = seg; + } + if (prevseg != undefined) { + /* add found segment to start of this sequence */ + log(this); + this.segments.unshift(prevseg); + log(this); + return this.select(); + } + } + } + offsetIntoSegment = 0; + } var eventOffsetMs = (segmentIdx * 60 * 1000) + offsetIntoSegment; var sequenceLengthMs = this.length() * 60 * 1000; var reloffset = eventOffsetMs / sequenceLengthMs;