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

98
LINES

< > BotCompany Repo | #1019770 // LAN Discovery [discovers other JavaX computers, formerly called "PC Awareness"]

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

Uses 108K of libraries. Click here for Pure Java version (19470L/146K).

1  
!7
2  
3  
!include #1015939 // PC Awareness Include
4  
5  
sclass PCAwareness > DynModule {
6  
  transient JLabel lblStatus;
7  
  
8  
  visualize { ret lblStatus; }
9  
10  
  start {
11  
    lblStatus = jcenteredboldlabel("Setting Up Awareness...");
12  
    
13  
    db();
14  
    
15  
    if (match("i am aware", sendToLocalBotOpt_original("Awareness Bot", "are you aware"))) {
16  
      setText(lblStatus, "Has awareness elsewhere.");
17  
      ret;
18  
    }
19  
    
20  
    swing {
21  
      awtOnConceptChanges(lblStatus, 1000, r updateStatus);
22  
      installTimer(lblStatus, 30000, r updateStatus);
23  
      
24  
      componentPopupMenu(lblStatus, voidfunc(JPopupMenu menu) {
25  
        for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) {
26  
          if (!validPeer(info) || eq(osName(info), "Android")) continue;
27  
          
28  
          // Remote PC popup items follow
29  
          addMenuItem(menu, "Grab clipboard from " + info.ip, r {
30  
            S s = sendToAwareness(info.ip, "get clipboard");
31  
            if (nempty(s) && neq(s, "empty or unknown")) {
32  
              L l = cast safeUnstructure(s);
33  
              S type = cast first(l);
34  
              if (eq(type, "text")) {
35  
                S text = (S) l.get(1);
36  
                copyTextToClipboard(text);
37  
                print("Copied text to clipboard: " + quote(shorten(text, 100)));
38  
              } else if (eq(type, "png")) {
39  
                copyImageToClipboard(fromPNG((byte[]) l.get(1)));
40  
                print("Copied image to clipboard.");
41  
              } else
42  
                print("Unknown clipboard type: " + type);
43  
            }
44  
          });
45  
          
46  
          addMenuItem(menu, "Grab screenshot from " + info.ip, r-thread {
47  
            loading "Grabbing Screenshot Through Network" {
48  
              S s = sendToAwareness(info.ip, "screenshot");
49  
              if (startsWith(s, "[")) {
50  
                L l = cast safeUnstructure(s);
51  
                S type = cast first(l);
52  
                if (eq(type, "png")) {
53  
                  BufferedImage img = fromPNG((byte[]) l.get(1));  
54  
                  showImage("Screenshot from " + info.ip + " at " + ymd_hms(), img);
55  
                }
56  
              }
57  
            }
58  
          });
59  
        }
60  
      });
61  
    }
62  
  
63  
    thread {
64  
      print("Yo Setting Up Awareness...");
65  
    
66  
      makeBot("Awareness Bot.");
67  
      phonePublicCommBot(); // works for PCs too
68  
      findBot_timeout = 1000*60;
69  
      pingThread(null);
70  
      
71  
      status("Awareness Set Up!");
72  
      printMyIPs();
73  
      
74  
      scanSubnet_parallel();
75  
    }
76  
  }
77  
78  
  void status(S s) {
79  
    setText(lblStatus, print(s));
80  
  }
81  
82  
  void updateStatus enter {
83  
    new L<S> l;
84  
    int meCount = 0;
85  
    for (MachineInfo info : concatLists(
86  
      findConcepts(MachineInfo, "me", true),
87  
      findConcepts(MachineInfo, "me", false))) {
88  
      if (!validPeer(info)) continue;
89  
      
90  
      l.add(info.ip + ": " + info.computerID /*osName(info)*/
91  
        + (info.me ? " [me]" : ""));
92  
      if (info.me) ++meCount;
93  
    }
94  
    S text = isEmpty(l) ? "Looking for peers"
95  
      : n(l(l)-max(0, meCount-1), "machine") + ": " + join(", ", l);
96  
    setText(lblStatus, text);
97  
  }
98  
}

Author comment

Began life as a copy of #1015941

download  show line numbers  debug dex  old transpilations   

Travelled to 10 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019770
Snippet name: LAN Discovery [discovers other JavaX computers, formerly called "PC Awareness"]
Eternal ID of this version: #1019770/11
Text MD5: eddfed79e01098934cbc67563c0851a4
Transpilation MD5: d2a7cf77f58af4b58163a51b19fec4e1
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-12 13:18:18
Source code size: 3161 bytes / 98 lines
Pitched / IR pitched: No / No
Views / Downloads: 309 / 1541
Version history: 10 change(s)
Referenced in: [show references]