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

52
LINES

< > BotCompany Repo | #1014677 // Eleu Live Log Using WebSockets (OK)

JavaX module [tags: ai1-lol butter use-pretranspiled] - homepage - homepage

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

!7

static Map<O, State> wsToState = weakHashMap();
static int nFirstChars = 256, interval = 200;

sclass State {
  S firstChars;
  int length;
  
  *() {}
  *(StringBuffer log) { init(log); }
  
  void init(StringBuffer log) {
    firstChars = stringBuffer_takeFirst(nFirstChars, log);
    length = 0;
  }
  
  bool valid(StringBuffer log) {
    ret eq(firstChars, stringBuffer_takeFirst(nFirstChars, log));
  }
}

static StringBuffer log() {
  ret (StringBuffer) get(mainBot(), 'local_log);
}

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

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

svoid update {
  StringBuffer log = log();
  for (O ws : webSocketManager.webSockets()) {
    State s = wsToState.get(ws);
    if (s == null) wsToState.put(ws, s = new State);
    if (!s.valid(log)) {
      s.init(log);
      call(ws, 'send, 'clear);
      continue;
    }
    S newStuff = stringBuffer_substring(log, s.length);
    if (nempty(newStuff)) {
      s.length = l(log);
      call(ws, 'send, "+" + newStuff);
    }
  }
}

Author comment

Began life as a copy of #1014675

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014677
Snippet name: Eleu Live Log Using WebSockets (OK)
Eternal ID of this version: #1014677/20
Text MD5: aa347b3f6c59d7fb4ba070e257869814
Transpilation MD5: 1420c5a61bd7854c57d2c7ae245d4ff1
Author: stefan
Category: javax / web
Type: JavaX module
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-09 12:10:28
Source code size: 1119 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 425 / 2952
Version history: 19 change(s)
Referenced in: [show references]