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