!7 cmodule CatEar > DynPrintLog { transient long timeout = 60000; transient int interval = 50; // TODO: use blocking wait int httpPort = 8082; S toSay; LS inputLines = synchroList(); LS outgoingLines = synchroList(); start-thread { dm_vmBus_onMessage androidCatShouldSay(vf say); ownResource(serveHttpFromFunction(httpPort, func(S uri, SS params) { if (!webAuthed(params)) { if (eq(uri, "/poll")) sleep(timeout); ret "not authed"; } S input = params.get('input); if (nempty(input)) { add(inputLines, input); printWithTime("Got input: " + input); vmBus_send('androidCatInput, module(), input); change(); } if (eq(uri, "/poll")) ret serveLongPoll(timeout, interval, func { LS l = getAndClearList(outgoingLines); if (empty(l)) null; for (S s : l) printWithTime("Served output: " + s); change(); ret lines_rtrim(l); }); ret "OK"; })); } void sayIt() { if (empty(toSay)) ret; add(outgoingLines, toSay); change(); } visual centerAndSouth(super, withMargin(dm_textFieldAndSubmit('toSay, 'sayIt))); // API void say(S s) enter { setField(toSay := s); sayIt(); } }