Add queue buffers & simulation support to web proxy

This makes a couple of major changes:
-Directly uses EPoll class for managing Seasocks events.
-Adds buffers of queues to web proxy Subscribers so that we can
 transfering data losslessly in log replay.
-Modifies the flatbuffer used for the RTC communications so that
 the webpage can specify whether it wants every message or subsampled
 messages.
-Adds an option to LogReader to let us run past the end of the logfile.

Note that these changes do mean that, for log replay, the web proxy will
load the *entire* logfile into memory. Future changes can optimize this
to, e.g., only load the required channels into memory.

Change-Id: I74e7608c30baa8b36e05c4ab50e12a54bf75aa4c
diff --git a/aos/network/www/plotter.ts b/aos/network/www/plotter.ts
index c10ff80..d33953c 100644
--- a/aos/network/www/plotter.ts
+++ b/aos/network/www/plotter.ts
@@ -35,8 +35,8 @@
   private _drawLine: boolean = true;
   private _pointSize: number = 3.0;
   private _hasUpdate: boolean = false;
-  private _minValues: number[] = [0.0, 0.0];
-  private _maxValues: number[] = [0.0, 0.0];
+  private _minValues: number[] = [Infinity, Infinity];
+  private _maxValues: number[] = [-Infinity, -Infinity];
   private _color: number[] = [1.0, 0.0, 0.0];
   private pointAttribLocation: number;
   private colorLocation: WebGLUniformLocation | null;
@@ -121,6 +121,10 @@
       const x = this.points[ii];
       const y = this.points[ii + 1];
 
+      if (isNaN(x) || isNaN(y)) {
+        continue;
+      }
+
       this._minValues = cwiseOp(this._minValues, [x, y], Math.min);
       this._maxValues = cwiseOp(this._maxValues, [x, y], Math.max);
     }
@@ -497,6 +501,9 @@
     for (let line of this.lines) {
       minValues = cwiseOp(minValues, line.minValues(), Math.min);
     }
+    if (!isFinite(minValues[0]) || !isFinite(minValues[1])) {
+      return [0, 0];
+    }
     return minValues;
   }
 
@@ -505,6 +512,9 @@
     for (let line of this.lines) {
       maxValues = cwiseOp(maxValues, line.maxValues(), Math.max);
     }
+    if (!isFinite(maxValues[0]) || !isFinite(maxValues[1])) {
+      return [0, 0];
+    }
     return maxValues;
   }
 
@@ -729,10 +739,12 @@
   private lastMousePosition: number[] = [0.0, 0.0];
   private autoFollow: boolean = true;
   private linkedXAxes: Plot[] = [];
+  private lastTimeMs: number = 0;
 
   constructor(wrapperDiv: HTMLDivElement, width: number, height: number) {
     wrapperDiv.appendChild(this.canvas);
     wrapperDiv.appendChild(this.textCanvas);
+    this.lastTimeMs = (new Date()).getTime();
 
     this.canvas.width =
         width - this.axisLabelBuffer.left - this.axisLabelBuffer.right;
@@ -838,6 +850,9 @@
   }
 
   setZoom(scale: number[], offset: number[]) {
+    if (!isFinite(scale[0]) || !isFinite(scale[1])) {
+      throw new Error("Doesn't support non-finite scales due to singularities.");
+    }
     const x_pressed = Plot.keysPressed["x"];
     const y_pressed = Plot.keysPressed["y"];
     const zoom = this.drawer.getZoom();
@@ -875,7 +890,17 @@
   }
 
   resetZoom() {
-    this.setZoomCorners(this.drawer.minValues(), this.drawer.maxValues());
+    const minValues = this.drawer.minValues();
+    const maxValues = this.drawer.maxValues();
+    if (minValues[0] == maxValues[0]) {
+      minValues[0] -= 1;
+      maxValues[0] += 1;
+    }
+    if (minValues[1] == maxValues[1]) {
+      minValues[1] -= 1;
+      maxValues[1] += 1;
+    }
+    this.setZoomCorners(minValues, maxValues);
     this.autoFollow = true;
     for (let plot of this.linkedXAxes) {
       plot.autoFollow = true;
@@ -892,6 +917,9 @@
 
   draw() {
     window.requestAnimationFrame(() => this.draw());
+    const curTime = (new Date()).getTime();
+    const frameRate = 1000.0 / (curTime - this.lastTimeMs);
+    this.lastTimeMs = curTime;
 
     // Clear the overlay.
     const textCtx = this.textCanvas.getContext("2d");