hsync 0.14.0 → 0.15.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/hsync-web.js CHANGED
@@ -10,27 +10,38 @@ window.Buffer = buffer.Buffer;
10
10
  setNet(net);
11
11
  setMqtt(mqtt);
12
12
 
13
- async function dynamicConnect(dynamicHost, useLocalStorage) {
13
+ async function dynamicConnect(dynamicHost, useLocalStorage, configObj = {}) {
14
+ if (typeof useLocalStorage === 'object') {
15
+ configObj = useLocalStorage;
16
+ }
17
+ else {
18
+ configObj.useLocalStorage = useLocalStorage;
19
+ }
20
+
21
+ const fullConfig = {...config, ...configObj};
22
+ if (fullConfig.net) {
23
+ setNet(fullConfig.net);
24
+ }
14
25
  let con;
15
26
  if (useLocalStorage) {
16
27
  const localConfigStr = localStorage.getItem('hsyncConfig');
17
28
  if (localConfigStr) {
18
29
  const localConfig = JSON.parse(localConfigStr);
19
30
  if ((Date.now() - localConfig.created) < (localConfig.timeout * 0.66)) {
20
- config.hsyncSecret = localConfig.hsyncSecret;
21
- config.hsyncServer = localConfig.hsyncServer;
31
+ fullConfig.hsyncSecret = localConfig.hsyncSecret;
32
+ fullConfig.hsyncServer = localConfig.hsyncServer;
22
33
  } else {
23
34
  localStorage.removeItem('hsyncConfig');
24
35
  }
25
36
  }
26
37
 
27
- if (!config.hsyncSecret) {
28
- config.dynamicHost = dynamicHost || config.defaultDynamicHost;
38
+ if (!fullConfig.hsyncSecret) {
39
+ fullConfig.dynamicHost = dynamicHost || fullConfig.defaultDynamicHost;
29
40
  }
30
41
 
31
- con = await createHsync(config);
42
+ con = await createHsync(fullConfig);
32
43
 
33
- if (config.dynamicHost) {
44
+ if (fullConfig.dynamicHost) {
34
45
  const storeConfig = {
35
46
  hsyncSecret: con.hsyncSecret,
36
47
  hsyncServer: con.hsyncServer,
@@ -43,8 +54,8 @@ async function dynamicConnect(dynamicHost, useLocalStorage) {
43
54
  return con;
44
55
  }
45
56
 
46
- config.dynamicHost = dynamicHost || config.defaultDynamicHost;
47
- con = await createHsync(config);
57
+ fullConfig.dynamicHost = dynamicHost || fullConfig.defaultDynamicHost;
58
+ con = await createHsync(fullConfig);
48
59
 
49
60
  return con;
50
61
 
package/hsync.js CHANGED
@@ -6,11 +6,12 @@ const config = require('./config');
6
6
  setNet(net);
7
7
  setMqtt(mqtt);
8
8
 
9
- async function dynamicConnect(dynamicHost) {
9
+ async function dynamicConnect(dynamicHost, configObj = {}) {
10
+ const fullConfig = {...config, ...configObj};
10
11
  let con;
11
12
 
12
- config.dynamicHost = dynamicHost || config.defaultDynamicHost;
13
- con = await createHsync(config);
13
+ fullConfig.dynamicHost = dynamicHost || fullConfig.defaultDynamicHost;
14
+ con = await createHsync(fullConfig);
14
15
 
15
16
  return con;
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hsync",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "client for hsync-server",
5
5
  "main": "hsync.js",
6
6
  "scripts": {