let json = serde_json::to_string(&json).expect("convert to json");
let update = PreparedUpdate {
gen,
- client,
- piece : vpiece,
- cseq : form.cseq,
- json,
+ u : PreparedPieceUpdate {
+ client,
+ sameclient_cseq : form.cseq,
+ piece : vpiece,
+ json,
+ },
};
let update = Arc::new(update);
// split vie wthing would go here, see also update.piece
#[derive(Debug)]
pub struct PreparedUpdate {
pub gen : Generation,
- pub client : ClientId,
- pub piece : VisiblePieceId,
- pub cseq : ClientSequence,
- pub json : String,
+ pub u : PreparedUpdatePayload,
+}
+#[derive(Debug)]
+pub enum PreparedUpdatePayload {
+ PreparedPieceUpdate {
+ client : ClientId,
+ sameclient_cseq : ClientSequence,
+ piece : VisiblePieceId,
+ json : String,
+ },
+}
+pub use PreparedUpdatePayload::*;
+
+impl PreparedUpdatePayload {
+ pub fn json_len(&self) -> usize { match self {
+ &PreparedPieceUpdate { ref json, .. } => json.len(),
+ } }
}
#[derive(Debug,Default)]
let next = match pu.log.get(self.to_send) {
Some(next) => next, None => { break }
};
- let next_len = UPDATE_MAX_FRAMING_SIZE + next.json.len();
+ let next_len = UPDATE_MAX_FRAMING_SIZE + next.u.json_len();
if next_len > buf.len() { break }
- if next.client == self.client {
- write!(buf, "event: recorded\n\
- data: ")?;
- serde_json::to_writer(&mut buf, &RecordedConfirmation {
- gen : next.gen,
- piece : next.piece,
- cseq : next.cseq,
- })?;
- write!(buf, "\n\n")?;
- } else {
- write!(buf, "id: {}\n\
- data: {}\n\n",
- &self.to_send,
- &next.json)?;
+ match &next.u {
+ &PreparedPieceUpdate {
+ piece, client : uclient, sameclient_cseq : cseq, ..
+ } if uclient== self.client => {
+ write!(buf, "event: recorded\n\
+ data: ")?;
+ serde_json::to_writer(&mut buf, &RecordedConfirmation {
+ gen : next.gen,
+ piece : piece,
+ cseq : cseq,
+ })?;
+ write!(buf, "\n\n")?;
+ },
+ PreparedPieceUpdate { json, .. } => {
+ write!(buf, "id: {}\n\
+ data: {}\n\n",
+ &self.to_send,
+ json)?;
+ },
}
self.to_send.try_increment().unwrap();
}
drag_uelem = null;
}
+// ----- logs -----
+
+messages.LogUpdate = function(data) {
+ lastent = logdiv.lastElementChild;
+ in_scrollback =
+ // inspired by
+ // https://stackoverflow.com/questions/487073/how-to-check-if-element-is-visible-after-scrolling/21627295#21627295
+ // rejected
+ // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
+ lastent.getBoundingClientRect().bottom >
+ logdiv.getBoundingClientRect().bottom;
+
+ console.log('LOG UPDATE ',in_scrollback,data);
+
+ if (!in_scrollback) {
+ lastent = logdiv.lastElementChild;
+ lastent.scrollIntoView();
+ }
+}
+
// ----- test counter, startup -----
messages.PieceUpdate = function(data) {
status_node.innerHTML = 'js-done'
dragthresh = 5;
space = document.getElementById('space');
+ logdiv = document.getElementById("log");
svg_ns = space.getAttribute('xmlns');
es = new EventSource("/_/updates/"+ctoken+'/'+gen);
<defs id="defs{{ piece.0 }}">{{ piece.1 }}</defs>
{%- endfor %}
</svg>
-<p>
- <div style="overflow-y: scroll; height: 200px;">
- Log item 1
- <br>
- Log item 2
- <br>
+
+ <div id="log" style="overflow-y: scroll; height: 200px;">
+ <div id="log1">Log item 1</div>
+ <div id="log2">Log item 2</div>
Log item 3
<br>
Log item 4
Log item 10
<br>
Log item 11
- <br>
- Log item 12
- </div>
+ <div id="log12">Log item 12</id>
+ </p>
</body>