websocket-text-relay 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +29 -0
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/docs/code-structure.md +77 -0
- package/docs/creating-text-editor-plugin.md +10 -0
- package/docs/dev-getting-started.md +8 -0
- package/index.js +87 -0
- package/package.json +45 -0
- package/src/language-server/JsonRpcInterface.js +126 -0
- package/src/language-server/JsonRpcInterface.test.js +496 -0
- package/src/language-server/LspReader.js +119 -0
- package/src/language-server/LspReader.test.js +508 -0
- package/src/language-server/LspWriter.js +44 -0
- package/src/language-server/LspWriter.test.js +179 -0
- package/src/language-server/constants.js +23 -0
- package/src/ui/css/fonts/Montserrat-Black.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-Bold.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-ExtraBold.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-ExtraLight.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-Light.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-Medium.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-Regular.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-SemiBold.ttf +0 -0
- package/src/ui/css/fonts/Montserrat-Thin.ttf +0 -0
- package/src/ui/css/fonts.css +54 -0
- package/src/ui/css/main.css +198 -0
- package/src/ui/index.html +36 -0
- package/src/ui/js/components/ActivityTimeseriesGraph.js +149 -0
- package/src/ui/js/components/HeaderSummary.js +23 -0
- package/src/ui/js/components/ServerStatus.js +31 -0
- package/src/ui/js/components/SessionLabels.js +171 -0
- package/src/ui/js/components/SessionWedges.js +107 -0
- package/src/ui/js/components/StatusRing.js +42 -0
- package/src/ui/js/components/grids.js +29 -0
- package/src/ui/js/index.js +117 -0
- package/src/ui/js/main.js +97 -0
- package/src/ui/js/util/DependencyManager.js +31 -0
- package/src/ui/js/util/EventEmitter.js +40 -0
- package/src/ui/js/util/WebsocketClient.js +76 -0
- package/src/ui/js/util/constants.js +9 -0
- package/src/ui/js/util/drawing.js +128 -0
- package/src/websocket-interface/WebsocketClient.js +56 -0
- package/src/websocket-interface/WebsocketInterface.js +71 -0
- package/src/websocket-interface/WtrSession.js +122 -0
- package/src/websocket-interface/httpServer.js +58 -0
- package/src/websocket-interface/sessionManager.js +107 -0
- package/src/websocket-interface/util.js +12 -0
- package/src/websocket-interface/websocketApi.js +116 -0
- package/src/websocket-interface/websocketServer.js +18 -0
- package/start.js +4 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { triggerStatusUpdate, statusEvents, addWatchedFileLinks, removeWatchedFileLinks, removeOpenedFileLinks, addOpenedFileLinks } from './sessionManager.js'
|
|
2
|
+
|
|
3
|
+
export const apiMethods = new Map([
|
|
4
|
+
["watch-log-messages", watchLogMessages],
|
|
5
|
+
["unwatch-log-messages", unwatchLogMessages],
|
|
6
|
+
["init", init],
|
|
7
|
+
["watch-file", watchFile],
|
|
8
|
+
["unwatch-file", unwatchFile],
|
|
9
|
+
["update-open-files", updateEditorOpenFiles],
|
|
10
|
+
["watch-editor-active-files", watchEditorActiveFiles],
|
|
11
|
+
["unwatch-editor-active-files", unwatchEditorActiveFiles],
|
|
12
|
+
["relay-text", relayText],
|
|
13
|
+
["watch-wtr-status", watchWtrStatus],
|
|
14
|
+
["unwatch-wtr-status", unwatchWtrStatus],
|
|
15
|
+
["watch-wtr-activity", watchWtrActivity],
|
|
16
|
+
["unwatch-wtr-activity", unwatchWtrActivity],
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
function watchLogMessages (wtrSession) {
|
|
20
|
+
wtrSession.watchLogMessages = true
|
|
21
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR log messages" })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function unwatchLogMessages (wtrSession) {
|
|
25
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR log messages" })
|
|
26
|
+
wtrSession.watchLogMessages = false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function init (wtrSession, data) {
|
|
30
|
+
wtrSession.name = data.name
|
|
31
|
+
wtrSession.editorPid = data.editorPid
|
|
32
|
+
wtrSession.lsPid = data.lsPid
|
|
33
|
+
triggerStatusUpdate()
|
|
34
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Init success" })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function watchFile (wtrSession, data) {
|
|
38
|
+
if (data.endsWith == null || data.endsWith.length === 0) {
|
|
39
|
+
wtrSession.emitter.emit('log', { level: "error", text: "Must provide an endsWith property" })
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
wtrSession.watchedFiles.add(data.endsWith)
|
|
43
|
+
addWatchedFileLinks(wtrSession, data.endsWith)
|
|
44
|
+
wtrSession.emitter.emit('log', { level: "info", text: `Watching files that end with ${data.endsWith}` })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function unwatchFile (wtrSession, data) {
|
|
48
|
+
if (data.endsWith == null || data.endsWith.length === 0) {
|
|
49
|
+
wtrSession.emitter.emit('log', { level: "error", text: "Must provide an endsWith property" })
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
wtrSession.watchedFiles.delete(data.endsWith)
|
|
53
|
+
removeWatchedFileLinks(wtrSession, data.endsWith)
|
|
54
|
+
wtrSession.emitter.emit('log', { level: "info", text: `No longer watching files that end with ${data.endsWith}` })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updateEditorOpenFiles (wtrSession, data) {
|
|
58
|
+
const updatedFileSet = new Set(data.files)
|
|
59
|
+
for (const fileName of wtrSession.openFiles) {
|
|
60
|
+
if (!updatedFileSet.has(fileName)) {
|
|
61
|
+
wtrSession.openFiles.delete(fileName)
|
|
62
|
+
removeOpenedFileLinks(wtrSession, fileName)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const fileName of updatedFileSet) {
|
|
66
|
+
if (!wtrSession.openFiles.has(fileName)) {
|
|
67
|
+
wtrSession.openFiles.add(fileName)
|
|
68
|
+
addOpenedFileLinks(wtrSession, fileName)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
triggerStatusUpdate()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function watchEditorActiveFiles (wtrSession) {
|
|
75
|
+
wtrSession.watchActiveFiles = true
|
|
76
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Watching editor active files" })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function unwatchEditorActiveFiles (wtrSession) {
|
|
80
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Unwatching editor active files" })
|
|
81
|
+
wtrSession.watchActiveFiles = false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function relayText (wtrSession, data) {
|
|
85
|
+
if (!data || !data.file) { return }
|
|
86
|
+
const {file, contents} = data
|
|
87
|
+
const watchers = wtrSession.activeOpenFiles.get(file)
|
|
88
|
+
if (!watchers) { return }
|
|
89
|
+
const watcherSessionIds = []
|
|
90
|
+
for (const {clientSession: watcherWtrSession, endsWith} of watchers.values()) {
|
|
91
|
+
watcherSessionIds.push(watcherWtrSession.id)
|
|
92
|
+
watcherWtrSession.sendMessageToClient({method: "watch-file", endsWith, contents})
|
|
93
|
+
}
|
|
94
|
+
const activityData = {action: "relay", relayer: wtrSession.id, watchers: watcherSessionIds}
|
|
95
|
+
statusEvents.emit('activity-update', activityData)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function watchWtrStatus (wtrSession) {
|
|
99
|
+
wtrSession.watchWtrStatus = true
|
|
100
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR status updates" })
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function unwatchWtrStatus (wtrSession) {
|
|
104
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR status updates" })
|
|
105
|
+
wtrSession.watchWtrStatus = false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function watchWtrActivity (wtrSession) {
|
|
109
|
+
wtrSession.watchWtrActivity = true
|
|
110
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR activity events" })
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function unwatchWtrActivity (wtrSession) {
|
|
114
|
+
wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR activity events" })
|
|
115
|
+
wtrSession.watchWtrActivity = false
|
|
116
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WebSocketServer } from 'ws'
|
|
2
|
+
import { createHttpServer } from "./httpServer.js"
|
|
3
|
+
import { apiMethods } from "./websocketApi.js"
|
|
4
|
+
import { WtrSession } from './WtrSession.js'
|
|
5
|
+
|
|
6
|
+
export const createWebsocketServer = async (port) => {
|
|
7
|
+
const httpServer = await createHttpServer(port) // promise will reject if can't start HTTP server on specified port
|
|
8
|
+
|
|
9
|
+
const websocketServer = new WebSocketServer({ server: httpServer })
|
|
10
|
+
|
|
11
|
+
websocketServer.on('error', () => { })
|
|
12
|
+
|
|
13
|
+
websocketServer.on('connection', (wsConnection) => {
|
|
14
|
+
new WtrSession({apiMethods, wsConnection})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return websocketServer
|
|
18
|
+
}
|
package/start.js
ADDED