statebus 6.1.17 → 6.1.21

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/client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  (function () {
2
- var unique_sockjs_string = '_connect_to_statebus_'
2
+ var websocket_prefix = (clientjs_option('websocket_path')
3
+ || '_connect_to_statebus_')
3
4
 
4
5
  window.dom = window.dom || new Proxy({}, {
5
6
  get: function (o, k) { return o[k] },
@@ -36,9 +37,9 @@
36
37
  // link.href = url
37
38
  // url = link.href
38
39
  // }
39
- console.log('opening websocket to', url)
40
- return new WebSocket(url + '/' + unique_sockjs_string + '/websocket')
41
- // return new SockJS(url + '/' + unique_sockjs_string)
40
+
41
+ return new WebSocket(url + '/' + websocket_prefix + '/websocket')
42
+ // return new SockJS(url + '/' + websocket_prefix)
42
43
  }
43
44
  function client_creds (server_url) {
44
45
  var me = bus.fetch('ls/me')
@@ -97,9 +98,9 @@
97
98
  subscribe: true,
98
99
  headers: {accept: 'application/json'}
99
100
  }
100
- ).andThen( x => {
101
+ ).andThen( function (x) {
101
102
  t.return({
102
- key,
103
+ key: key,
103
104
  val: add_prefixes(JSON.parse(x.body))
104
105
  })
105
106
  })
@@ -452,11 +453,10 @@
452
453
  window.ignore_flashbacks = false
453
454
  if (statebus_server !== 'none') {
454
455
  if (clientjs_option('braid_mode')) {
455
- console.log('We socket-free!')
456
+ console.log('Using Braid-HTTP!')
456
457
  braid_http_mount ('/*', statebus_server)
457
458
  } else {
458
459
  bus.net_mount ('/*', statebus_server)
459
- console.log('We going websocket!')
460
460
  }
461
461
  }
462
462
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "6.1.17",
3
+ "version": "6.1.21",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/server.js CHANGED
@@ -1,6 +1,5 @@
1
1
  var fs = require('fs'),
2
2
  util = require('util')
3
- var unique_sockjs_string = '_connect_to_statebus_'
4
3
 
5
4
  // Import braidify if it's available
6
5
  try {
@@ -22,6 +21,7 @@ function default_options (bus) { return {
22
21
  certificate: 'certs/certificate',
23
22
  certificate_bundle: 'certs/certificate-bundle'},
24
23
  connections: {include_users: true, edit_others: true},
24
+ websocket_path: '_connect_to_statebus_',
25
25
  __secure: false
26
26
  }}
27
27
 
@@ -106,11 +106,6 @@ function import_server (bus, options)
106
106
  bus.sync_files(x.state_path, x.fs_path)
107
107
  })
108
108
 
109
- bus.express.use((req, res, next) => {
110
- console.log('server.js:', req.method, req.url)
111
- next()
112
- })
113
-
114
109
  // Free the CORS for Braid requests!
115
110
  bus.express.use((req, res, next) => {
116
111
  // If this requests knows about Braid then we presume the
@@ -391,7 +386,8 @@ function import_server (bus, options)
391
386
  this.http_server.on('request', // Install express
392
387
  function (request, response) {
393
388
  // But express should ignore all sockjs requests
394
- if (!request.url.startsWith('/'+unique_sockjs_string+'/'))
389
+ if (!request.url.startsWith(
390
+ '/' + bus.options.websocket_path + '/'))
395
391
  express_app(request, response)
396
392
  })
397
393
 
@@ -591,7 +587,7 @@ function import_server (bus, options)
591
587
  }
592
588
  })
593
589
 
594
- s.installHandlers(httpserver, {prefix:'/' + unique_sockjs_string})
590
+ s.installHandlers(httpserver, {prefix:'/' + bus.options.websocket_path})
595
591
  },
596
592
 
597
593
  make_websocket: function make_websocket (url) {
@@ -599,7 +595,7 @@ function import_server (bus, options)
599
595
  url = url.replace(/^istate:\/\//, 'ws://')
600
596
  url = url.replace(/^statei:\/\//, 'ws://')
601
597
  WebSocket = require('websocket').w3cwebsocket
602
- return new WebSocket(url+'/'+unique_sockjs_string+'/websocket')
598
+ return new WebSocket(url+'/'+bus.options.websocket_path+'/websocket')
603
599
  },
604
600
  client_creds: function client_creds (server_url) {
605
601
  // Right now the server just creates a different random id each time
package/statebus.js CHANGED
@@ -10,10 +10,12 @@
10
10
  // Fetch, Save, Forget, Delete
11
11
 
12
12
  function fetch (key, callback) {
13
+ if (typeof key !== 'string'
14
+ && !(typeof key === 'object' && typeof key.key === 'string'))
15
+ throw ('Error: fetch(key) called with key = '
16
+ + JSON.stringify(key))
13
17
  key = key.key || key // You can pass in an object instead of key
14
18
  // We should probably disable this in future
15
- if (typeof key !== 'string')
16
- throw ('Error: fetch(key) called with a non-string key: '+key)
17
19
  bogus_check(key)
18
20
 
19
21
  var called_from_reactive_funk = !callback