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

58
LINES

< > BotCompany Repo | #1023280 // Android Controller (port 8082, control the cat on the phone, OLD version for single user)

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6526L/36K).

1  
!7
2  
3  
cmodule CatEar > DynPrintLog {
4  
  transient long timeout = 60000;
5  
  transient int interval = 50; // TODO: use blocking wait
6  
  int httpPort = 8082;
7  
  
8  
  S toSay;
9  
  LS inputLines = synchroList();
10  
  LS outgoingLines = synchroList();
11  
12  
  start-thread {
13  
    dm_vmBus_onMessage androidCatShouldSay(vf<S> say);
14  
    ownResource(serveHttpFromFunction(httpPort, func(S uri, SS params) {
15  
      if (!webAuthed(params)) {
16  
        if (eq(uri, "/poll"))
17  
          sleep(timeout);
18  
        ret "not authed";
19  
      }
20  
      
21  
      S input = params.get('input);
22  
      if (nempty(input)) {
23  
        add(inputLines, input);
24  
        printWithTime("Got input: " + input);
25  
        vmBus_send('androidCatInput, module(), input);
26  
        change();
27  
      }
28  
  
29  
      if (eq(uri, "/poll"))
30  
        ret serveLongPoll(timeout, interval, func {
31  
          LS l = getAndClearList(outgoingLines);
32  
          if (empty(l)) null;
33  
          for (S s : l)
34  
            printWithTime("Served output: " + s);
35  
          change();
36  
          ret lines_rtrim(l);
37  
        });
38  
        
39  
      ret "OK";
40  
    }));
41  
  }
42  
  
43  
  void sayIt() {
44  
    if (empty(toSay)) ret;
45  
    add(outgoingLines, toSay);
46  
    change();
47  
  }
48  
  
49  
  visual centerAndSouth(super,
50  
    withMargin(dm_textFieldAndSubmit('toSay, 'sayIt)));
51  
    
52  
  // API
53  
  
54  
  void say(S s) enter {
55  
    setField(toSay := s);
56  
    sayIt();
57  
  }
58  
}

Author comment

Began life as a copy of #1014866

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023280
Snippet name: Android Controller (port 8082, control the cat on the phone, OLD version for single user)
Eternal ID of this version: #1023280/16
Text MD5: 970edf592f0a58d4aeb30a163443eeaf
Transpilation MD5: 897564a112e59888e175db2dc5373bc8
Author: stefan
Category: javax / web / a.i. / android
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-11 19:32:56
Source code size: 1394 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 333 / 9796
Version history: 15 change(s)
Referenced in: [show references]