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).

!7

!include #1015939 // PC Awareness Include

sclass PCAwareness > DynModule {
  transient JLabel lblStatus;
  
  visualize { ret lblStatus; }

  start {
    lblStatus = jcenteredboldlabel("Setting Up Awareness...");
    
    db();
    
    if (match("i am aware", sendToLocalBotOpt_original("Awareness Bot", "are you aware"))) {
      setText(lblStatus, "Has awareness elsewhere.");
      ret;
    }
    
    swing {
      awtOnConceptChanges(lblStatus, 1000, r updateStatus);
      installTimer(lblStatus, 30000, r updateStatus);
      
      componentPopupMenu(lblStatus, voidfunc(JPopupMenu menu) {
        for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) {
          if (!validPeer(info) || eq(osName(info), "Android")) continue;
          
          // Remote PC popup items follow
          addMenuItem(menu, "Grab clipboard from " + info.ip, r {
            S s = sendToAwareness(info.ip, "get clipboard");
            if (nempty(s) && neq(s, "empty or unknown")) {
              L l = cast safeUnstructure(s);
              S type = cast first(l);
              if (eq(type, "text")) {
                S text = (S) l.get(1);
                copyTextToClipboard(text);
                print("Copied text to clipboard: " + quote(shorten(text, 100)));
              } else if (eq(type, "png")) {
                copyImageToClipboard(fromPNG((byte[]) l.get(1)));
                print("Copied image to clipboard.");
              } else
                print("Unknown clipboard type: " + type);
            }
          });
          
          addMenuItem(menu, "Grab screenshot from " + info.ip, r-thread {
            loading "Grabbing Screenshot Through Network" {
              S s = sendToAwareness(info.ip, "screenshot");
              if (startsWith(s, "[")) {
                L l = cast safeUnstructure(s);
                S type = cast first(l);
                if (eq(type, "png")) {
                  BufferedImage img = fromPNG((byte[]) l.get(1));  
                  showImage("Screenshot from " + info.ip + " at " + ymd_hms(), img);
                }
              }
            }
          });
        }
      });
    }
  
    thread {
      print("Yo Setting Up Awareness...");
    
      makeBot("Awareness Bot.");
      phonePublicCommBot(); // works for PCs too
      findBot_timeout = 1000*60;
      pingThread(null);
      
      status("Awareness Set Up!");
      printMyIPs();
      
      scanSubnet_parallel();
    }
  }

  void status(S s) {
    setText(lblStatus, print(s));
  }

  void updateStatus enter {
    new L<S> l;
    int meCount = 0;
    for (MachineInfo info : concatLists(
      findConcepts(MachineInfo, "me", true),
      findConcepts(MachineInfo, "me", false))) {
      if (!validPeer(info)) continue;
      
      l.add(info.ip + ": " + info.computerID /*osName(info)*/
        + (info.me ? " [me]" : ""));
      if (info.me) ++meCount;
    }
    S text = isEmpty(l) ? "Looking for peers"
      : n(l(l)-max(0, meCount-1), "machine") + ": " + join(", ", l);
    setText(lblStatus, text);
  }
}

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: 326 / 1563
Version history: 10 change(s)
Referenced in: [show references]