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).

1  
!7
2  
3  
static Map<O, State> wsToState = weakHashMap();
4  
static int nFirstChars = 256, interval = 200;
5  
6  
sclass State {
7  
  S firstChars;
8  
  int length;
9  
  
10  
  *() {}
11  
  *(StringBuffer log) { init(log); }
12  
  
13  
  void init(StringBuffer log) {
14  
    firstChars = stringBuffer_takeFirst(nFirstChars, log);
15  
    length = 0;
16  
  }
17  
  
18  
  bool valid(StringBuffer log) {
19  
    ret eq(firstChars, stringBuffer_takeFirst(nFirstChars, log));
20  
  }
21  
}
22  
23  
static StringBuffer log() {
24  
  ret (StringBuffer) get(mainBot(), 'local_log);
25  
}
26  
27  
p {
28  
  initWebSockets();
29  
  doEvery(interval, f update);
30  
}
31  
32  
html {
33  
  ret htitle_h3("Eleu Live Log") + subBot_html_webSocketBasedLogView();
34  
}
35  
36  
svoid update {
37  
  StringBuffer log = log();
38  
  for (O ws : webSocketManager.webSockets()) {
39  
    State s = wsToState.get(ws);
40  
    if (s == null) wsToState.put(ws, s = new State);
41  
    if (!s.valid(log)) {
42  
      s.init(log);
43  
      call(ws, 'send, 'clear);
44  
      continue;
45  
    }
46  
    S newStuff = stringBuffer_substring(log, s.length);
47  
    if (nempty(newStuff)) {
48  
      s.length = l(log);
49  
      call(ws, 'send, "+" + newStuff);
50  
    }
51  
  }
52  
}

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: 559 / 3328
Version history: 19 change(s)
Referenced in: [show references]