Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1014682 // Mech Changes Live Log (OK)

JavaX source code (desktop) [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Download Jar. Libraryless. Click here for Pure Java version (2739L/18K).

!7

static Map<O, Long> wsToState = weakHashMap();
static int interval = 200, initialChars = 65536;
static long timeout = 10*60000L; // larger timeout since we have no idle mechanism yet (otherwise screen flickers sometimes)

static File fileToLog() { ret getProgramFile(#1013927, "versions.log"); }

p {
  initWebSockets();
  doEvery(interval, f update);
}

html { ret htitle_h3("Mech Live Log") + subBot_html_webSocketBasedLogView(); }

svoid update {
  if (webSocketManager.isEmpty()) ret;
  File f = fileToLog();
  long len = fileSize(f);
  
  for (O ws : webSocketManager.webSockets()) {
    Long l = wsToState.get(ws);
    if (l == null) {
      set(ws, 'timeout, timeout);
      wsToState.put(ws, l = max(0, len-initialChars));
      call(ws, 'send, 'clear);
    }
    if (len > l) {
      S newStuff = unquoteAllLines(loadTextFilePart(f, l, len));
      wsToState.put(ws, len);
      call(ws, 'send, "+" + newStuff);
    }
  }
}

Author comment

Began life as a copy of #1014677

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1014682
Snippet name: Mech Changes Live Log (OK)
Eternal ID of this version: #1014682/19
Text MD5: a71b20501b2aee6e56dea26d85d34137
Transpilation MD5: af97534c46d8123ab51cc5648ac9a47e
Author: stefan
Category: javax / a.i. / web
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-30 02:16:49
Source code size: 969 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 427 / 2847
Version history: 18 change(s)
Referenced in: [show references]