!7 static Map wsToState = weakHashMap(); static int nFirstChars = 256; 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 { void onNewWebSocket(O ws, S uri) { super.onNewWebSocket(ws, uri); wsToState.put(ws, new State(log())); } }; doEvery(1000, 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) continue; 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); } } }