!7 static Map wsToState = weakHashMap(); static int nFirstChars = 256, interval = 200; sclass State { S firstChars; int length; *() {} *(StringBuffer log) { init(log); //length = l(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(), 'print_log); } p { webSocketManager = new WebSocketManager; doEvery(interval, f update); } html { ret htitle_h3("Eleu Live Log") + loadJQuery() + hpre("", id := 'results) + hreconnectingWebSockets() + hjs_htmlencode() + hjavascript([[ var ws = new ReconnectingWebSocket("${URI}"); ws.onmessage = function(event) { var d = event.data; if (d == "clear") $("#results").html(""); else { $("#results").append(htmlencode(d.substring(1))); window.scrollTo(0, 1000000); } }; ]].replace("${URI}", subBot_myWebSocketURI()); } svoid update { StringBuffer log = log(); for (O ws : webSocketManager.webSockets) { State s = wsToState.get(ws); if (s == null) wsToState.put(ws, s = new State(log)); 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); } } }