connects to that WebSocket and does things via those message buses
| 44 | /** |
| 45 | * connects to that WebSocket and does things via those message buses |
| 46 | */ |
| 47 | public class RemoteEditor extends Box { |
| 48 | |
| 49 | static public final Dict.Prop<EditorUtils> editorUtils = new Dict.Prop<EditorUtils>("editorUtils").toCanon() |
| 50 | .doc("utility class for manipulating the editor at a high level"); |
| 51 | |
| 52 | static public final Dict.Prop<Supplier<Map<Pair<String, String>, Runnable>>> hotkeyCommands = new Dict.Prop<>("hotkeyCommands").type() |
| 53 | .doc("commands injected into the editor as hotkey menuSpecs") |
| 54 | .toCanon(); |
| 55 | static public final Dict.Prop<RemoteEditor> editor = new Dict.Prop<>("editor").type() |
| 56 | .doc("the (remote) editor object") |
| 57 | .toCanon(); |
| 58 | static public final Dict.Prop<Function<Box, Consumer<String>>> outputFactory = new Dict.Prop<>("outputFactory"); |
| 59 | static public final Dict.Prop<Function<Box, Consumer<Pair<Integer, String>>>> outputErrorFactory = new Dict.Prop<>("outputErrorFactory"); |
| 60 | static public final Dict.Prop<Function<Box, BiConsumer<String, JSONObject>>> outputMessageFactory = new Dict.Prop<>("outputMessageFactory"); |
| 61 | |
| 62 | static public final Dict.Prop<String> defaultEditorProperty = new Dict.Prop<String>("defaultEditorProperty").type() |
| 63 | .doc("The property that the editor will switch to. Will default to 'code' if not set."); |
| 64 | private final Server server; |
| 65 | |
| 66 | private String socketName; |
| 67 | |
| 68 | private final MessageQueue<Quad<Dict.Prop, Box, Object, Object>, String> queue; |
| 69 | private final Watches watches; |
| 70 | public List<Consumer<String>> logStack = new ArrayList<>(); |
| 71 | public List<Consumer<String>> errorStack = new ArrayList<>(); |
| 72 | public HashMap<String, String> previousClipboards = new LinkedHashMap<>(); |
| 73 | Commands commandHelper = new Commands(); |
| 74 | |
| 75 | RateLimitingQueue<String, Pair<String, String>> rater = new RateLimitingQueue<>(20, 100) { |
| 76 | |
| 77 | Deque<Long> overflowedAt = new LinkedList<>(); |
| 78 | |
| 79 | @Override |
| 80 | protected String groupFor(Pair<String, String> stringRunnablePair) { |
| 81 | return stringRunnablePair.first; |
| 82 | } |
| 83 | |
| 84 | String lastSend = ""; |
| 85 | boolean warned = false; |
| 86 | long prevTick = RunLoop.tick; |
| 87 | |
| 88 | @Override |
| 89 | protected void send(String key, Collection<Pair<String, String>> value) { |
| 90 | |
| 91 | // if (value.size() == 0) return; |
| 92 | |
| 93 | int index = 0; |
| 94 | for (Pair<String, String> v : value) { |
| 95 | System.out.println(" --> " + v.second); |
| 96 | server.send(socketName, "_messageBus.publish('" + key + "', " + v.second + ")"); |
| 97 | if (index++ > 4) { |
| 98 | System.out.println(" limit exceeded (" + value.size() + ")"); |
| 99 | //TODO, notify... |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | // } |