@knowlearning/agents 0.9.81 → 0.9.83
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 +3 -3
- package/agents/generic/message-queue.js +3 -3
- package/deno.js +1 -0
- package/package.json +1 -1
package/agents/browser/root.js
CHANGED
|
@@ -14,11 +14,11 @@ export default options => {
|
|
|
14
14
|
const Connection = function () {
|
|
15
15
|
const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST}`)
|
|
16
16
|
|
|
17
|
-
this.send = message => ws.send(message)
|
|
17
|
+
this.send = message => ws.send(JSON.stringify(message))
|
|
18
18
|
this.close = () => ws.close()
|
|
19
19
|
|
|
20
|
-
ws.onopen = () => this.onopen
|
|
21
|
-
ws.onmessage = ({ data }) => this.onmessage
|
|
20
|
+
ws.onopen = () => this.onopen()
|
|
21
|
+
ws.onmessage = ({ data }) => this.onmessage(data)
|
|
22
22
|
ws.onerror = error => this.onerror && this.onerror(error)
|
|
23
23
|
ws.onclose = error => this.onclose && this.onclose(error)
|
|
24
24
|
|
|
@@ -69,7 +69,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
|
|
|
69
69
|
while (authed && lastSentSI+1 < messageQueue.length) {
|
|
70
70
|
lastSynchronousScopePatched = null
|
|
71
71
|
try {
|
|
72
|
-
connection.send(
|
|
72
|
+
connection.send(messageQueue[lastSentSI + 1])
|
|
73
73
|
lastSentSI += 1
|
|
74
74
|
// async so we don't try and push more to a closed connection
|
|
75
75
|
await new Promise(r=>r())
|
|
@@ -121,7 +121,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
|
|
|
121
121
|
if (!sessionMetrics.connected) sessionMetrics.connected = Date.now()
|
|
122
122
|
log('AUTHORIZING NEWLY OPENED CONNECTION FOR SESSION:', session)
|
|
123
123
|
failedConnections = 0
|
|
124
|
-
connection.send(
|
|
124
|
+
connection.send({ token: await token(), session })
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
connection.onmessage = async data => {
|
|
@@ -167,7 +167,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
|
|
|
167
167
|
.forEach(([res, rej]) => message.error ? rej(message) : res(message))
|
|
168
168
|
|
|
169
169
|
delete responses[message.si]
|
|
170
|
-
connection.send(
|
|
170
|
+
connection.send({ack: message.si}) // acknowledgement that we have received the response for this message
|
|
171
171
|
resolveSyncPromises()
|
|
172
172
|
}
|
|
173
173
|
else {
|
package/deno.js
CHANGED
|
@@ -12,6 +12,7 @@ function Connection() {
|
|
|
12
12
|
|
|
13
13
|
const delay = new Promise(r => setTimeout(r))
|
|
14
14
|
delay.then(() => thisConnection.onopen())
|
|
15
|
+
denoProcess.onmessage = ({ data }) => thisConnection.onmessage(data)
|
|
15
16
|
|
|
16
17
|
// TODO: consider what onclose and onerror mean in this case
|
|
17
18
|
return thisConnection
|