@knowlearning/agents 0.9.89 → 0.9.91

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.
@@ -4,18 +4,23 @@ import { getToken, login, logout } from './auth.js'
4
4
  import GenericAgent from '../generic/index.js'
5
5
 
6
6
  const DEVELOPMENT_HOST = 'localhost:32001'
7
- const REMOTE_HOST = 'api.knowlearning.systems'
7
+ const REMOTE_HOST = localStorage.getItem('mode') === 'staging' ? 'api.staging.knowlearning.systems' : 'api.knowlearning.systems'
8
8
 
9
9
  function isLocal() { return localStorage.getItem('api') === 'local' }
10
10
 
11
+ const API_HOST = isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST
12
+
11
13
  export default options => {
12
14
  const { host, protocol } = window.location
13
15
 
14
16
  const Connection = function () {
15
- const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST}`)
17
+ const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${API_HOST}`)
16
18
 
17
19
  this.send = message => ws.send(JSON.stringify(message))
18
- this.close = () => ws.close()
20
+ this.close = info => {
21
+ this.send({ type: 'close', info })
22
+ ws.close()
23
+ }
19
24
 
20
25
  ws.onopen = () => this.onopen()
21
26
  ws.onmessage = ({ data }) => this.onmessage(data.length === 0 ? null : JSON.parse(data))
@@ -37,15 +42,12 @@ export default options => {
37
42
  })
38
43
 
39
44
  agent.local = () => {
40
- if (isLocal()) return
41
-
42
45
  localStorage.setItem('api', 'local')
43
46
  location.reload()
44
47
  }
45
- agent.remote = () => {
46
- if (!isLocal()) return
47
-
48
- localStorage.removeItem('api')
48
+ agent.remote = (mode='production') => {
49
+ localStorage.setItem('api', 'remote')
50
+ localStorage.setItem('mode', mode)
49
51
  location.reload()
50
52
  }
51
53
  agent.close = () => {
@@ -236,7 +236,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
236
236
  function disconnect() {
237
237
  log('DISCONNECTED AGENT!!!!!!!!!!!!!!!')
238
238
  disconnected = true
239
- connection.close()
239
+ connection.close({ keepalive: true })
240
240
  }
241
241
 
242
242
  function reconnect() {
package/deno.js CHANGED
@@ -32,7 +32,6 @@ const agent = new Agent({
32
32
  // this functionality is only implemented for the deno
33
33
  // agent for now, but this central management of children
34
34
  // concept probably has a place in the generic agent
35
- console.log('DOMAIN AGENT RECEIVED MESSAGE!!!!!!!!!!!!!!!!!!', type, session, data)
36
35
  if (type === 'open') {
37
36
  const child = {
38
37
  on: (eventType, reaction) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.89",
3
+ "version": "0.9.91",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",