Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
isExpired(currentTime: Time) {
// cannot tell if a marker is expired if we don't have a clock yet
if (!currentTime) {
return false;
}
const lifetime = this.getLifetime();
// we use the receive time (clock) instead of the header stamp
// to match the behavior of rviz
const expiresAt = TimeUtil.add(this.receiveTime, lifetime);
return TimeUtil.isGreaterThan(currentTime, expiresAt);
}
const { activeData, playerId } = context.playerState;
if (!playerId || !activeData) {
return;
}
if (seekApplied.current) {
return;
}
seekApplied.current = true;
const params = new URLSearchParams(search);
const seekTo = parseInt(params.get("seek-to"), 10);
if (!seekTo) {
return;
}
const { startTime, endTime } = activeData;
const seekToTime = fromMillis(seekTo);
if (TimeUtil.isGreaterThan(seekToTime, startTime) && TimeUtil.isLessThan(seekToTime, endTime)) {
context.seekPlayback(seekToTime);
}
},
[shouldRunEffect, search] // eslint-disable-line react-hooks/exhaustive-deps
async getMessages(start: Time, end: Time, topics: string[]) {
const result = [];
for (const message of this.messages) {
if (TimeUtil.isGreaterThan(message.receiveTime, end)) {
break;
}
if (TimeUtil.isLessThan(message.receiveTime, start)) {
continue;
}
if (!topics.includes(message.topic)) {
continue;
}
result.push(message);
}
return result;
}
}
TimeUtil.isLessThan(start, this._current.start)
) {
this._topics = topics;
this._current = undefined;
this._next = undefined;
}
let messages = [];
const currentMatches = this._current && this._current.overlaps(start, end);
const nextMatches = this._next && this._next.overlaps(start, end);
if (/*:: this._current && */ currentMatches) {
messages = messages.concat(await this._current.getMessages(start, end));
}
if (/*:: this._next && */ nextMatches) {
messages = messages.concat(await this._next.getMessages(start, end));
}
if ((!currentMatches && !nextMatches) || (this._next && TimeUtil.isGreaterThan(end, this._next.end))) {
let startTime = start;
if (/*:: this._next && */ nextMatches) {
startTime = TimeUtil.add(this._next.end, oneNanoSecond);
log.info("readahead cache overrun - consider expanding readAheadRange");
}
this._current = this._makeReadResult(startTime, end, topics);
await this._current.getMessages(startTime, end);
const nextStart = TimeUtil.add(end, oneNanoSecond);
this._next = this._makeReadResult(nextStart, TimeUtil.add(nextStart, this._readAheadRange), topics);
messages = messages.concat(await this._getMessages(startTime, end, topics));
} else if (/*:: this._next && */ nextMatches) {
this._current = this._next;
const nextStart = TimeUtil.add(this._current.end, oneNanoSecond);
const nextEnd = TimeUtil.add(nextStart, this._readAheadRange);
this._next = this._makeReadResult(nextStart, nextEnd, topics);
}
setClock(clock: Time) {
if (!clock) {
return;
}
const clockMovedBackwards = TimeUtil.isGreaterThan(this.clock, clock);
if (clockMovedBackwards) {
this.markers.forEach((marker, key) => {
const markerReceivedAfterClock = TimeUtil.isGreaterThan(marker.receiveTime, clock);
if (markerReceivedAfterClock) {
this.markers.delete(key);
}
});
}
this.clock = clock;
}
const merge = (messages1: DataProviderMessage[], messages2: DataProviderMessage[]) => {
const messages = [];
let index1 = 0;
let index2 = 0;
while (index1 < messages1.length && index2 < messages2.length) {
if (TimeUtil.isGreaterThan(messages1[index1].receiveTime, messages2[index2].receiveTime)) {
messages.push(messages2[index2++]);
} else {
messages.push(messages1[index1++]);
}
}
while (index1 < messages1.length) {
messages.push(messages1[index1++]);
}
while (index2 < messages2.length) {
messages.push(messages2[index2++]);
}
return messages;
};
this.markers.forEach((marker, key) => {
const markerReceivedAfterClock = TimeUtil.isGreaterThan(marker.receiveTime, clock);
if (markerReceivedAfterClock) {
this.markers.delete(key);
}
});
}