Libraryless. Click here for Pure Java version (14996L/109K).
1 | !7 |
2 | |
3 | sclass MachineChat extends DynPrintLog { |
4 | S receiver, msg; |
5 | bool sign; |
6 | transient StefansOS_ConnectToServer connector; |
7 | |
8 | visualize { |
9 | ret centerAndSouthWithMargins( |
10 | super.visualize(), |
11 | westCenterAndEastWithMargin( |
12 | jLine( |
13 | jLabel("Send to"), |
14 | jMinWidth(100, jLiveValueTextField_bothWays(dm_fieldLiveValue('receiver))), |
15 | jLabel(":")), |
16 | onEnterAndCtrlEnter(jLiveValueTextField_bothWays(dm_fieldLiveValue('msg)), rThread sendMsg), |
17 | jLine( |
18 | jLiveValueCheckBox("Sign", dm_fieldLiveValue('sign)), |
19 | jbutton("Send", rThread sendMsg)))); |
20 | } |
21 | |
22 | void sendMsg { |
23 | postMsg(receiver, msg, sign); |
24 | setField(msg := ""); |
25 | } |
26 | |
27 | void postSigned(S receiver, S msg) { postMsg(receiver, msg, true); } |
28 | void postMsg(S receiver, S msg, bool sign) { |
29 | if (empty(receiver = trim(receiver))) ret; |
30 | if (!possibleComputerID(receiver)) ret with infoBox("Not a computer ID: " + receiver); |
31 | if (empty(msg = trim(msg))) ret; |
32 | if (sign) msg = signWithComputerIDAndDate(msg); |
33 | vmBus_send('sendingToPrivateMachineChat, receiver, msg); |
34 | //logQuotedWithDate(javaxDataDir("OS Chat/sent.log"), msg); |
35 | print("Sending to " + receiver + ": " + shorten(msg, 200)); |
36 | connector.sendLine("privateMachineChat:" + receiver + " " + quote(msg)); |
37 | } |
38 | |
39 | void cleanMeUp { cleanUp(connector); } |
40 | |
41 | start { |
42 | thread { exportComputerPublicKeyToServerMechList(); } |
43 | connector = new StefansOS_ConnectToServer; |
44 | connector.onLine = voidfunc(S line) { |
45 | new Matches m; |
46 | if (startsWith(line, "privateMachineChat:privately from ", m)) { |
47 | S s = m.rest(); |
48 | int i = indexOf(s, ':'); |
49 | S sender = takeFirst(s, i); |
50 | S msg = unquote(substring(s, i+2)); |
51 | printWithIndent(sender + " >> ", shorten(msg, 1000)); |
52 | vmBus_send('gotFromPrivateMachineChat, sender, msg); |
53 | //logQuotedWithDate(stefansOS_chat_receivedLogFile(), msg); |
54 | } |
55 | }; |
56 | connector.startWithSubs("privateMachineChat"); |
57 | } |
58 | } |
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: | 295 / 2241 |
Version history: | 4 change(s) |
Referenced in: | [show references] |