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

58
LINES

< > BotCompany Repo | #1019685 // Machine-to-machine Chat [one-on-one; use #1019644 to chat between humans]

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

Libraryless. Click here for Pure Java version (14996L/109K).

!7

sclass MachineChat extends DynPrintLog {
  S receiver, msg;
  bool sign;
  transient StefansOS_ConnectToServer connector;
  
  visualize {
    ret centerAndSouthWithMargins(
      super.visualize(),
      westCenterAndEastWithMargin(
        jLine(
          jLabel("Send to"),
          jMinWidth(100, jLiveValueTextField_bothWays(dm_fieldLiveValue('receiver))),
          jLabel(":")),
        onEnterAndCtrlEnter(jLiveValueTextField_bothWays(dm_fieldLiveValue('msg)), rThread sendMsg),
        jLine(
          jLiveValueCheckBox("Sign", dm_fieldLiveValue('sign)),
          jbutton("Send", rThread sendMsg))));
  }
  
  void sendMsg {
    postMsg(receiver, msg, sign);
    setField(msg := "");
  }
  
  void postSigned(S receiver, S msg) { postMsg(receiver, msg, true); }
  void postMsg(S receiver, S msg, bool sign) {
    if (empty(receiver = trim(receiver))) ret;
    if (!possibleComputerID(receiver)) ret with infoBox("Not a computer ID: " + receiver);
    if (empty(msg = trim(msg))) ret;
    if (sign) msg = signWithComputerIDAndDate(msg);
    vmBus_send('sendingToPrivateMachineChat, receiver, msg);
    //logQuotedWithDate(javaxDataDir("OS Chat/sent.log"), msg);
    print("Sending to " + receiver + ": " + shorten(msg, 200));
    connector.sendLine("privateMachineChat:" + receiver + " " + quote(msg));
  }
  
  void cleanMeUp { cleanUp(connector); }
  
  start {
    thread { exportComputerPublicKeyToServerMechList(); }
    connector = new StefansOS_ConnectToServer;
    connector.onLine = voidfunc(S line) {
      new Matches m;
      if (startsWith(line, "privateMachineChat:privately from ", m)) {
        S s = m.rest();
        int i = indexOf(s, ':');
        S sender = takeFirst(s, i);
        S msg = unquote(substring(s, i+2));
        printWithIndent(sender + " >> ", shorten(msg, 1000));
        vmBus_send('gotFromPrivateMachineChat, sender, msg);
        //logQuotedWithDate(stefansOS_chat_receivedLogFile(), msg);
      }
    };
    connector.startWithSubs("privateMachineChat");
  }
}

Author comment

Began life as a copy of #1019644

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1019685
Snippet name: Machine-to-machine Chat [one-on-one; use #1019644 to chat between humans]
Eternal ID of this version: #1019685/5
Text MD5: 1daa12bdebba7b8a9461a5e7963097a2
Transpilation MD5: 4950f22434dd696ead181cdee9904b0b
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-19 14:54:19
Source code size: 2076 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 209 / 2124
Version history: 4 change(s)
Referenced in: [show references]