@knowlearning/agents 0.0.9 → 0.1.1
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/agents/browser/root.js +2 -1
- package/agents/deno.js +2 -1
- package/agents/generic.js +18 -4
- package/agents/node.js +2 -1
- package/package/browser.js +3 -2
- package/package.json +1 -1
- package/vue/3/component.js +1 -1
- package/vue/3/component.shim.js +4 -0
package/agents/browser/root.js
CHANGED
package/agents/deno.js
CHANGED
package/agents/generic.js
CHANGED
|
@@ -12,7 +12,7 @@ function sanitizeJSONPatchPathSegment(s) {
|
|
|
12
12
|
else return s
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout }) {
|
|
15
|
+
export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout, reboot }) {
|
|
16
16
|
let ws
|
|
17
17
|
let user
|
|
18
18
|
let domain
|
|
@@ -27,6 +27,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
27
27
|
const messageQueue = []
|
|
28
28
|
let resolveEnvironment
|
|
29
29
|
let disconnected = false
|
|
30
|
+
let failedConnections = 0
|
|
30
31
|
const environment = new Promise(r => resolveEnvironment = r)
|
|
31
32
|
|
|
32
33
|
const sessionData = new MutableProxy({}, patch => queueMessage({scope: 'sessions', patch}))
|
|
@@ -59,6 +60,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
59
60
|
this.disconnect = disconnect
|
|
60
61
|
this.reconnect = reconnect
|
|
61
62
|
|
|
63
|
+
console.log('INITIALIZING AGENT CONNECTION')
|
|
62
64
|
initWS()
|
|
63
65
|
|
|
64
66
|
let lastSentSI = -1
|
|
@@ -85,7 +87,11 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
85
87
|
function initWS() {
|
|
86
88
|
ws = new WebSocket(`${protocol}://${host}`)
|
|
87
89
|
|
|
88
|
-
ws.onopen = async () =>
|
|
90
|
+
ws.onopen = async () => {
|
|
91
|
+
console.log('AUTHORIZING NEWLY OPENED WS FOR SESSION:', session)
|
|
92
|
+
failedConnections = 0
|
|
93
|
+
ws.send(JSON.stringify({ token: await token, session }))
|
|
94
|
+
}
|
|
89
95
|
|
|
90
96
|
ws.onmessage = async ({ data }) => {
|
|
91
97
|
try {
|
|
@@ -100,6 +106,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
100
106
|
server = message.server
|
|
101
107
|
resolveEnvironment(message)
|
|
102
108
|
}
|
|
109
|
+
else if (server !== message.server) {
|
|
110
|
+
console.warn(`REBOOTING DUE TO SERVER SWITCH ${server} -> ${message.server}`)
|
|
111
|
+
reboot()
|
|
112
|
+
}
|
|
103
113
|
else {
|
|
104
114
|
lastSentSI = message.ack
|
|
105
115
|
}
|
|
@@ -148,9 +158,13 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
ws.onclose = async () => {
|
|
161
|
+
if (authed) console.log(`CLOSED DOMAIN ${domain} USER ${user} SESSION ${session} CONNECTION TO SERVER ${server}`)
|
|
151
162
|
authed = false
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
if (!disconnected) {
|
|
164
|
+
await new Promise(r => setTimeout(r, Math.min(1000, failedConnections * 100)))
|
|
165
|
+
failedConnections += 1
|
|
166
|
+
initWS() // TODO: don't do this if we are purposefully unloading...
|
|
167
|
+
}
|
|
154
168
|
}
|
|
155
169
|
}
|
|
156
170
|
|
package/agents/node.js
CHANGED
package/package/browser.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// TODO: export browser, node, deno, and generic agents
|
|
2
2
|
export { default as BrowserAgent } from '../agents/browser/embedded.js'
|
|
3
3
|
export { default as GenericAgent } from '../agents/generic.js'
|
|
4
|
-
export { default as
|
|
5
|
-
export { default as vueContentComponent } from '../vue/3/content.vue'
|
|
4
|
+
export { default as vuePersistentStore } from '../persistence/vuex.js'
|
|
5
|
+
export { default as vueContentComponent } from '../vue/3/content.vue'
|
|
6
|
+
export { default as vuePersistentComponent } from '../vue/3/component.js'
|
package/package.json
CHANGED
package/vue/3/component.js
CHANGED