iosignal 1.7.0 → 1.8.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -247
  3. package/auth_file.json +13 -13
  4. package/auth_file.mjs +23 -23
  5. package/dist/iosignal-iife.js +11 -0
  6. package/dist/iosignal-iife.js.map +1 -0
  7. package/dist/iosignal.cjs +1 -2
  8. package/dist/iosignal.js +11 -0
  9. package/dist/iosignal.js.map +1 -0
  10. package/index.js +19 -19
  11. package/indexWebBrowser.js +13 -13
  12. package/package.json +56 -59
  13. package/rollup.config.js +72 -69
  14. package/src/api/RedisAPI.js +65 -65
  15. package/src/api/api_constant.js +7 -7
  16. package/src/api/api_reply.js +31 -31
  17. package/src/api/api_sudo.js +91 -91
  18. package/src/auth/Auth_Env.js +76 -76
  19. package/src/auth/Auth_File.js +71 -71
  20. package/src/auth/Auth_Redis.js +44 -44
  21. package/src/auth/BohoAuth.js +164 -164
  22. package/src/client/CongPacket.js +141 -141
  23. package/src/client/IOCongSocket.js +81 -81
  24. package/src/client/IOCore.js +822 -822
  25. package/src/client/IOWS.js +80 -80
  26. package/src/client/IOWebSocket.js +111 -111
  27. package/src/common/constants.js +148 -148
  28. package/src/common/payload.js +81 -81
  29. package/src/common/quotaTable.js +68 -68
  30. package/src/common/util.js +61 -61
  31. package/src/server/FileLogger.js +30 -30
  32. package/src/server/Manager.js +433 -433
  33. package/src/server/Metric.js +155 -155
  34. package/src/server/Remote.js +207 -207
  35. package/src/server/RemoteCore.js +439 -439
  36. package/src/server/Server.js +163 -163
  37. package/src/server/serverOption.js +56 -56
  38. package/test-browser/favicon.ico +0 -0
  39. package/test-browser/index.html +96 -96
  40. package/test-browser/server.js +11 -11
  41. package/test-client-nodejs/client.cjs +17 -17
  42. package/test-client-nodejs/client.mjs +17 -17
  43. package/test-client-nodejs/client_api_reply.mjs +15 -15
  44. package/test-client-nodejs/stateChange.mjs +19 -19
  45. package/test-server/server-Auth_Env.js +19 -19
  46. package/test-server/server-Auth_File.js +12 -12
  47. package/test-server/server-api_reply.js +6 -6
  48. package/test-server/server-api_sudo.js +7 -7
  49. package/test-server/server-commonjs.cjs +8 -8
  50. package/test-server/server-esm.mjs +20 -20
  51. package/test-server/simple-server.mjs +11 -11
  52. package/test-signal-payloadType/signalPack.js +34 -34
  53. package/test-signal-payloadType/signaling.js +60 -60
  54. package/dist/iosignal.esm.js +0 -3
  55. package/dist/iosignal.esm.js.map +0 -1
  56. package/dist/iosignal.min.js +0 -3
  57. package/dist/iosignal.min.js.map +0 -1
@@ -1,91 +1,91 @@
1
- import { STATUS } from './api_constant.js'
2
-
3
- const MIN_LEVEL = 255;
4
-
5
- export const commands = [
6
- 'cid', 'remotes', 'clients',
7
- 'channels', 'subscribers',
8
- 'remote', 'client', 'close',
9
- 'addauth', 'getauth', 'delauth',
10
- 'getauthidlist', 'getdevicelist',
11
- 'adddevice', 'getdevice', 'deldevice'
12
- ]
13
-
14
-
15
- export function checkPermission(remote) {
16
- if (remote.level >= MIN_LEVEL) {
17
- return true
18
- } else {
19
- return false
20
- }
21
- }
22
-
23
- export async function request(remote, req) {
24
- let result;
25
- let status = 0;
26
- try {
27
- let cmd = req.topic;
28
- cmd = cmd.toLowerCase()
29
- if (cmd == 'cid') {
30
- result = remote.manager.metric.getCIdList()
31
- } else if (cmd == 'remotes' || cmd == 'clients') {
32
- result = remote.manager.metric.getRemotes()
33
- } else if (cmd == 'channels') {
34
- result = remote.manager.metric.getChannelList()
35
- } else if (cmd == 'subscribers') {
36
- let ch = req.$[0]
37
- if (ch) result = remote.manager.metric.getSubscribers(ch)
38
- } else if (cmd == 'remote' || cmd == 'client') {
39
- let cid = req.$[0]
40
- let mode = req.$[1]
41
- if (cid) result = remote.manager.metric.getRemoteByCId(cid, mode)
42
-
43
- } else if (cmd == 'close') {
44
- if (req.$[0]) result = remote.manager.closeRemoteByCId(req.$[0])
45
-
46
- } else if (cmd == 'addauth' || cmd == 'adddevice') {
47
- if (remote.manager.authManager && req.$.length == 4) {
48
- if (remote.manager.authManager.addAuth) {
49
- let did = req.$[0]
50
- let dkey = req.$[1]
51
- let cid = req.$[2]
52
- let level = req.$[3]
53
- result = await remote.manager.authManager.addAuth(did, dkey, cid, level)
54
- }
55
-
56
- }
57
- } else if (cmd == 'delauth' || cmd == 'deldevice') {
58
- if (remote.manager.authManager && req.$.length == 1) {
59
- if (remote.manager.authManager.delAuth) {
60
- let did = req.$[0]
61
- result = await remote.manager.authManager.delAuth(did)
62
- }
63
- }
64
- } else if (cmd == 'getauth' || cmd == 'getdevice') {
65
- if (remote.manager.authManager && req.$.length == 1) {
66
- if (remote.manager.authManager.getAuth) {
67
- let did = req.$[0]
68
- result = await remote.manager.authManager.getAuth(did)
69
- }
70
- }
71
- } else if (cmd == 'getauthidlist' || cmd == 'getdevicelist') {
72
- if (remote.manager.authManager) {
73
- if (remote.manager.authManager.getAuthIdList) {
74
- result = await remote.manager.authManager.getAuthIdList()
75
- }
76
- }
77
- } else {
78
- status = STATUS.ERROR;
79
- result = "api sudo: no such a cmd: " + cmd
80
- }
81
-
82
- remote.response(req.mid, status, result)
83
-
84
- } catch (e) {
85
- remote.response(req.mid, STATUS.ERROR, e.message)
86
- }
87
-
88
- }
89
-
90
-
91
-
1
+ import { STATUS } from './api_constant.js'
2
+
3
+ const MIN_LEVEL = 255;
4
+
5
+ export const commands = [
6
+ 'cid', 'remotes', 'clients',
7
+ 'channels', 'subscribers',
8
+ 'remote', 'client', 'close',
9
+ 'addauth', 'getauth', 'delauth',
10
+ 'getauthidlist', 'getdevicelist',
11
+ 'adddevice', 'getdevice', 'deldevice'
12
+ ]
13
+
14
+
15
+ export function checkPermission(remote) {
16
+ if (remote.level >= MIN_LEVEL) {
17
+ return true
18
+ } else {
19
+ return false
20
+ }
21
+ }
22
+
23
+ export async function request(remote, req) {
24
+ let result;
25
+ let status = 0;
26
+ try {
27
+ let cmd = req.topic;
28
+ cmd = cmd.toLowerCase()
29
+ if (cmd == 'cid') {
30
+ result = remote.manager.metric.getCIdList()
31
+ } else if (cmd == 'remotes' || cmd == 'clients') {
32
+ result = remote.manager.metric.getRemotes()
33
+ } else if (cmd == 'channels') {
34
+ result = remote.manager.metric.getChannelList()
35
+ } else if (cmd == 'subscribers') {
36
+ let ch = req.$[0]
37
+ if (ch) result = remote.manager.metric.getSubscribers(ch)
38
+ } else if (cmd == 'remote' || cmd == 'client') {
39
+ let cid = req.$[0]
40
+ let mode = req.$[1]
41
+ if (cid) result = remote.manager.metric.getRemoteByCId(cid, mode)
42
+
43
+ } else if (cmd == 'close') {
44
+ if (req.$[0]) result = remote.manager.closeRemoteByCId(req.$[0])
45
+
46
+ } else if (cmd == 'addauth' || cmd == 'adddevice') {
47
+ if (remote.manager.authManager && req.$.length == 4) {
48
+ if (remote.manager.authManager.addAuth) {
49
+ let did = req.$[0]
50
+ let dkey = req.$[1]
51
+ let cid = req.$[2]
52
+ let level = req.$[3]
53
+ result = await remote.manager.authManager.addAuth(did, dkey, cid, level)
54
+ }
55
+
56
+ }
57
+ } else if (cmd == 'delauth' || cmd == 'deldevice') {
58
+ if (remote.manager.authManager && req.$.length == 1) {
59
+ if (remote.manager.authManager.delAuth) {
60
+ let did = req.$[0]
61
+ result = await remote.manager.authManager.delAuth(did)
62
+ }
63
+ }
64
+ } else if (cmd == 'getauth' || cmd == 'getdevice') {
65
+ if (remote.manager.authManager && req.$.length == 1) {
66
+ if (remote.manager.authManager.getAuth) {
67
+ let did = req.$[0]
68
+ result = await remote.manager.authManager.getAuth(did)
69
+ }
70
+ }
71
+ } else if (cmd == 'getauthidlist' || cmd == 'getdevicelist') {
72
+ if (remote.manager.authManager) {
73
+ if (remote.manager.authManager.getAuthIdList) {
74
+ result = await remote.manager.authManager.getAuthIdList()
75
+ }
76
+ }
77
+ } else {
78
+ status = STATUS.ERROR;
79
+ result = "api sudo: no such a cmd: " + cmd
80
+ }
81
+
82
+ remote.response(req.mid, status, result)
83
+
84
+ } catch (e) {
85
+ remote.response(req.mid, STATUS.ERROR, e.message)
86
+ }
87
+
88
+ }
89
+
90
+
91
+
@@ -1,76 +1,76 @@
1
- /**
2
- * Auth_Env.js
3
- *
4
- * You can use environment variable BOHO_AUTH.
5
- *
6
- * BOHO_AUTH=id1.key1.level,id2:key2.level
7
- *
8
- * or constructor parameter.
9
- *
10
- *
11
- * [ authInfo ]
12
- * id: <String> max 8chars
13
- * key: <String>
14
- * level: <Numbrer> range: 0~255
15
- * separator: ','
16
- *
17
- * example => process.env.BOHO_AUTH=id1.key1.255,id2.key2.200
18
- */
19
-
20
- import { BohoAuth } from './BohoAuth.js';
21
- import { sha256 } from 'boho'
22
-
23
- export class Auth_Env extends BohoAuth {
24
- constructor(authInfo) {
25
- super()
26
- let id_keys;
27
- if (authInfo) {
28
- id_keys = authInfo.split(',')
29
- } else if (process.env.BOHO_AUTH) {
30
- authInfo = process.env.BOHO_AUTH
31
- id_keys = process.env.BOHO_AUTH.split(',')
32
- } else {
33
- console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo")
34
- process.exit()
35
- }
36
-
37
- this.AUTH = new Map();
38
-
39
- if (id_keys.length >= 1) {
40
- id_keys.forEach(v => {
41
-
42
- let did = v.split('.')[0]
43
- let key = v.split('.')[1]
44
- let level = v.split('.')[2]
45
- level = parseInt(level)
46
-
47
- if (did && key && typeof level == 'number') {
48
- let cid = did;
49
- this.addAuth(did, key, cid, level)
50
- } else {
51
- console.log("Wrong process.env.BOHO_AUTH authentication value.", id, key, level)
52
- process.exit();
53
- }
54
- })
55
-
56
- } else {
57
- console.log("Wrong process.env.BOHO_AUTH authentication value.")
58
- process.exit();
59
- }
60
-
61
- }
62
-
63
- async getAuth(id) {
64
- return this.AUTH.get(id)
65
- }
66
- async getAuthIdList() {
67
- return Array.from(this.AUTH.keys())
68
- }
69
-
70
- addAuth(id, keyStr, cid, level = 0) {
71
- let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
72
- this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
73
- }
74
-
75
- }
76
-
1
+ /**
2
+ * Auth_Env.js
3
+ *
4
+ * You can use environment variable BOHO_AUTH.
5
+ *
6
+ * BOHO_AUTH=id1.key1.level,id2:key2.level
7
+ *
8
+ * or constructor parameter.
9
+ *
10
+ *
11
+ * [ authInfo ]
12
+ * id: <String> max 8chars
13
+ * key: <String>
14
+ * level: <Numbrer> range: 0~255
15
+ * separator: ','
16
+ *
17
+ * example => process.env.BOHO_AUTH=id1.key1.255,id2.key2.200
18
+ */
19
+
20
+ import { BohoAuth } from './BohoAuth.js';
21
+ import { sha256 } from 'boho'
22
+
23
+ export class Auth_Env extends BohoAuth {
24
+ constructor(authInfo) {
25
+ super()
26
+ let id_keys;
27
+ if (authInfo) {
28
+ id_keys = authInfo.split(',')
29
+ } else if (process.env.BOHO_AUTH) {
30
+ authInfo = process.env.BOHO_AUTH
31
+ id_keys = process.env.BOHO_AUTH.split(',')
32
+ } else {
33
+ console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo")
34
+ process.exit()
35
+ }
36
+
37
+ this.AUTH = new Map();
38
+
39
+ if (id_keys.length >= 1) {
40
+ id_keys.forEach(v => {
41
+
42
+ let did = v.split('.')[0]
43
+ let key = v.split('.')[1]
44
+ let level = v.split('.')[2]
45
+ level = parseInt(level)
46
+
47
+ if (did && key && typeof level == 'number') {
48
+ let cid = did;
49
+ this.addAuth(did, key, cid, level)
50
+ } else {
51
+ console.log("Wrong process.env.BOHO_AUTH authentication value.", id, key, level)
52
+ process.exit();
53
+ }
54
+ })
55
+
56
+ } else {
57
+ console.log("Wrong process.env.BOHO_AUTH authentication value.")
58
+ process.exit();
59
+ }
60
+
61
+ }
62
+
63
+ async getAuth(id) {
64
+ return this.AUTH.get(id)
65
+ }
66
+ async getAuthIdList() {
67
+ return Array.from(this.AUTH.keys())
68
+ }
69
+
70
+ addAuth(id, keyStr, cid, level = 0) {
71
+ let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
72
+ this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
73
+ }
74
+
75
+ }
76
+
@@ -1,71 +1,71 @@
1
- import { BohoAuth } from './BohoAuth.js';
2
- import { readFileSync } from 'fs'
3
- import { sha256 } from 'boho'
4
- import path from 'path'
5
-
6
- export class Auth_File extends BohoAuth {
7
- constructor(_path) {
8
- super()
9
- this.AUTH = new Map();
10
- let pathObj = path.parse(_path)
11
- this.path = path.resolve(_path)
12
- console.log('auth from file path:', this.path)
13
- let ext = pathObj.ext;
14
- if (ext.toLowerCase() == '.js' || ext.toLowerCase() == '.mjs') {
15
- // Read auth data from file
16
- console.log("#JS path:", this.path);
17
- this.loadAuthInfoFile_JS(this.path)
18
- } else if (ext.toLowerCase() == '.json') {
19
- console.log("#JSON path:", this.path);
20
- this.loadAuthInfoFile_JSON(this.path)
21
- } else {
22
- console.log('no authinfofile path.')
23
- }
24
- }
25
-
26
-
27
- async getAuth(id) {
28
- return this.AUTH.get(id)
29
- }
30
-
31
- async getAuthIdList() {
32
- return Array.from(this.AUTH.keys())
33
- }
34
-
35
- //loaded when server start.
36
- loadAuthInfoFile_JS(path) {
37
-
38
- import(path).then((file) => {
39
-
40
- console.log(file.authInfo);
41
- file.authInfo.forEach(item => {
42
- this.addAuth(...item)
43
- })
44
- console.log('total AUTH INFO size: ', this.AUTH.size)
45
- }).catch(e => {
46
- console.log(e)
47
- })
48
-
49
-
50
- }
51
-
52
- loadAuthInfoFile_JSON(path) {
53
- let file = readFileSync(path)
54
- file = new TextDecoder().decode(file)
55
- let list = JSON.parse(file)
56
- list.forEach(item => {
57
- this.addAuth(...item)
58
- })
59
- console.log('total AUTH INFO size: ', this.AUTH.size)
60
-
61
- }
62
-
63
- addAuth(id, keyStr, cid, level = 0) {
64
- let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
65
- this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
66
- }
67
-
68
-
69
-
70
- }
71
-
1
+ import { BohoAuth } from './BohoAuth.js';
2
+ import { readFileSync } from 'fs'
3
+ import { sha256 } from 'boho'
4
+ import path from 'path'
5
+
6
+ export class Auth_File extends BohoAuth {
7
+ constructor(_path) {
8
+ super()
9
+ this.AUTH = new Map();
10
+ let pathObj = path.parse(_path)
11
+ this.path = path.resolve(_path)
12
+ console.log('auth from file path:', this.path)
13
+ let ext = pathObj.ext;
14
+ if (ext.toLowerCase() == '.js' || ext.toLowerCase() == '.mjs') {
15
+ // Read auth data from file
16
+ console.log("#JS path:", this.path);
17
+ this.loadAuthInfoFile_JS(this.path)
18
+ } else if (ext.toLowerCase() == '.json') {
19
+ console.log("#JSON path:", this.path);
20
+ this.loadAuthInfoFile_JSON(this.path)
21
+ } else {
22
+ console.log('no authinfofile path.')
23
+ }
24
+ }
25
+
26
+
27
+ async getAuth(id) {
28
+ return this.AUTH.get(id)
29
+ }
30
+
31
+ async getAuthIdList() {
32
+ return Array.from(this.AUTH.keys())
33
+ }
34
+
35
+ //loaded when server start.
36
+ loadAuthInfoFile_JS(path) {
37
+
38
+ import(path).then((file) => {
39
+
40
+ console.log(file.authInfo);
41
+ file.authInfo.forEach(item => {
42
+ this.addAuth(...item)
43
+ })
44
+ console.log('total AUTH INFO size: ', this.AUTH.size)
45
+ }).catch(e => {
46
+ console.log(e)
47
+ })
48
+
49
+
50
+ }
51
+
52
+ loadAuthInfoFile_JSON(path) {
53
+ let file = readFileSync(path)
54
+ file = new TextDecoder().decode(file)
55
+ let list = JSON.parse(file)
56
+ list.forEach(item => {
57
+ this.addAuth(...item)
58
+ })
59
+ console.log('total AUTH INFO size: ', this.AUTH.size)
60
+
61
+ }
62
+
63
+ addAuth(id, keyStr, cid, level = 0) {
64
+ let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
65
+ this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
66
+ }
67
+
68
+
69
+
70
+ }
71
+
@@ -1,44 +1,44 @@
1
- import { BohoAuth } from './BohoAuth.js';
2
- import { sha256 } from 'boho'
3
- const DEVICE_PREFIX = "device:"
4
-
5
- export class Auth_Redis extends BohoAuth {
6
- constructor(redisClient) {
7
- super()
8
- if (!redisClient) {
9
- throw new Error("AuthRedis constructor: no redisClient")
10
- }
11
- this.redis = redisClient
12
- }
13
-
14
- // get device key from DB. (for Boho auth.)
15
- async getAuth(id) {
16
- let result = await this.redis.hGetAll(DEVICE_PREFIX + id)
17
- if (result.key) return result
18
- }
19
-
20
-
21
- async getAuthIdList() {
22
- let result = await this.redis.keys(DEVICE_PREFIX + '*')
23
- result = result.map(v => {
24
- return v.split(':')[1]
25
- })
26
- if (result) return result
27
- }
28
-
29
- // add device auth info
30
- async addAuth(id, keyStr, cid = '', level = 0) {
31
- let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
32
- return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
33
- }
34
-
35
- async delAuth(id) {
36
- return this.redis.del(DEVICE_PREFIX + id)
37
- }
38
-
39
- async save(id) {
40
- return this.redis.save()
41
- }
42
-
43
- }
44
-
1
+ import { BohoAuth } from './BohoAuth.js';
2
+ import { sha256 } from 'boho'
3
+ const DEVICE_PREFIX = "device:"
4
+
5
+ export class Auth_Redis extends BohoAuth {
6
+ constructor(redisClient) {
7
+ super()
8
+ if (!redisClient) {
9
+ throw new Error("AuthRedis constructor: no redisClient")
10
+ }
11
+ this.redis = redisClient
12
+ }
13
+
14
+ // get device key from DB. (for Boho auth.)
15
+ async getAuth(id) {
16
+ let result = await this.redis.hGetAll(DEVICE_PREFIX + id)
17
+ if (result.key) return result
18
+ }
19
+
20
+
21
+ async getAuthIdList() {
22
+ let result = await this.redis.keys(DEVICE_PREFIX + '*')
23
+ result = result.map(v => {
24
+ return v.split(':')[1]
25
+ })
26
+ if (result) return result
27
+ }
28
+
29
+ // add device auth info
30
+ async addAuth(id, keyStr, cid = '', level = 0) {
31
+ let Base64hashKey = Buffer.from(sha256.hash(keyStr)).toString('base64')
32
+ return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
33
+ }
34
+
35
+ async delAuth(id) {
36
+ return this.redis.del(DEVICE_PREFIX + id)
37
+ }
38
+
39
+ async save(id) {
40
+ return this.redis.save()
41
+ }
42
+
43
+ }
44
+