iosignal-cli 4.5.0 → 4.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.
- package/{auth_file.js → auth_file_sample/auth_file.js} +2 -5
- package/auth_file_sample/auth_file.json +9 -0
- package/bin/io-client.js +20 -14
- package/bin/io-server.js +15 -15
- package/package.json +2 -2
- package/auth_file.json +0 -13
|
@@ -3,17 +3,14 @@
|
|
|
3
3
|
Authentication data sample.
|
|
4
4
|
|
|
5
5
|
device props: ["did", "key", "cid", level ]
|
|
6
|
-
|
|
7
6
|
did: ( device id ) authentication id. maximum 8 chars.
|
|
8
|
-
key: ( device key ) authentication key. no size limit.
|
|
7
|
+
key: ( device key ) authentication key. no size limit. recommended ~44 base64 chars.
|
|
9
8
|
cid: ( communication id ) signal target id. maximum 12 chars.
|
|
10
|
-
level:( quota level) <Number> ref. /
|
|
9
|
+
level:( quota level) <Number> ref. /src/common/quotaTable.js
|
|
11
10
|
|
|
12
11
|
*/
|
|
13
12
|
export const authInfo = [
|
|
14
13
|
["did","passowrd","cid",0],
|
|
15
|
-
["device1","device1_key","device1_cid",0],
|
|
16
|
-
["device2","device2_key","device2_cid",0],
|
|
17
14
|
["uno","uno-key","uno",1],
|
|
18
15
|
["go","go-key","go",2],
|
|
19
16
|
["bro","bro-key","bro",3],
|
package/bin/io-client.js
CHANGED
|
@@ -167,7 +167,8 @@ io.on('ready', () => {
|
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
io.on('close', () => {
|
|
170
|
-
|
|
170
|
+
let date = new Date().toLocaleTimeString()
|
|
171
|
+
wsConsole.print(Console.Types.Control, `closed ${date}`, Console.Colors.Yellow)
|
|
171
172
|
})
|
|
172
173
|
|
|
173
174
|
|
|
@@ -206,7 +207,13 @@ io.on('iam_res', (...args) => {
|
|
|
206
207
|
})
|
|
207
208
|
|
|
208
209
|
io.on('message',(tag,...args)=>{
|
|
209
|
-
|
|
210
|
+
let msg ;
|
|
211
|
+
if(typeof args[0] == 'object'){
|
|
212
|
+
msg = JSON.stringify( args[0])
|
|
213
|
+
}else{
|
|
214
|
+
msg = args;
|
|
215
|
+
}
|
|
216
|
+
wsConsole.print(Console.Types.Incoming, `message: ${tag} ${msg}`, Console.Colors.Green)
|
|
210
217
|
})
|
|
211
218
|
|
|
212
219
|
wsConsole.on('line', (data) => {
|
|
@@ -255,7 +262,7 @@ wsConsole.on('line', (data) => {
|
|
|
255
262
|
case 'sudo':
|
|
256
263
|
toks.shift()
|
|
257
264
|
console.log('sudo toks', toks)
|
|
258
|
-
io.
|
|
265
|
+
io.call('sudo', ...toks).then(res => {
|
|
259
266
|
if (res.ok) {
|
|
260
267
|
console.log('>> sudo response:', res.body)
|
|
261
268
|
} else {
|
|
@@ -304,18 +311,17 @@ wsConsole.on('line', (data) => {
|
|
|
304
311
|
io.set(toks[1])
|
|
305
312
|
break;
|
|
306
313
|
|
|
307
|
-
case '
|
|
308
|
-
case 'req':
|
|
314
|
+
case 'call':
|
|
309
315
|
toks.shift()
|
|
310
316
|
if (toks.length < 2) {
|
|
311
317
|
wsConsole.print(
|
|
312
318
|
Console.Types.Error,
|
|
313
|
-
'[.
|
|
319
|
+
'[.call need at least two params] call target command [, ..args]',
|
|
314
320
|
Console.Colors.Yellow
|
|
315
321
|
)
|
|
316
322
|
return
|
|
317
323
|
}
|
|
318
|
-
io.
|
|
324
|
+
io.call(...toks).then(result => {
|
|
319
325
|
console.log('>> response:', result)
|
|
320
326
|
}).catch(e => {
|
|
321
327
|
console.log(e)
|
|
@@ -328,13 +334,13 @@ wsConsole.on('line', (data) => {
|
|
|
328
334
|
case 'listen':
|
|
329
335
|
toks.shift()
|
|
330
336
|
let tag = toks[0]
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
if(tag){
|
|
338
|
+
io.subscribe( tag )
|
|
339
|
+
let tagList = tag.split(',')
|
|
340
|
+
tagList.forEach( (v)=>{
|
|
341
|
+
io.channels.add( v )
|
|
342
|
+
})
|
|
343
|
+
}
|
|
338
344
|
break;
|
|
339
345
|
|
|
340
346
|
|
package/bin/io-server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createClient } from 'redis';
|
|
|
4
4
|
import { program } from 'commander'
|
|
5
5
|
import { serverInfo } from './serverInfo.js';
|
|
6
6
|
import {
|
|
7
|
-
Server, serverOption,
|
|
7
|
+
Server, serverOption, replyService, sudoService, RedisService, version as iosignal_version,
|
|
8
8
|
BohoAuth, FileKeyProvider, StringKeyProvider, RedisKeyProvider
|
|
9
9
|
} from 'iosignal'
|
|
10
10
|
|
|
@@ -19,14 +19,13 @@ program
|
|
|
19
19
|
.option('-l, --listen <port>', 'listen on port (start WebSocket Server)')
|
|
20
20
|
.option('-L, --listen-congport <port>', 'listen on cong port (start CongSocket Server)')
|
|
21
21
|
.option('-d, --auth-file <path>', 'auth data file path')
|
|
22
|
-
.option('-e, --auth-param <id.key.level>', 'auth data from argument:
|
|
23
|
-
.option('-E, --auth-env', 'auth data from shell env BOHO_AUTH')
|
|
22
|
+
.option('-e, --auth-param <id.key.level>', 'auth data from argument: id1.key.cid1.level1,id2.key2.cid2.level2')
|
|
24
23
|
.option('-r, --auth-redis', 'connect to redis. if exist use env REDIS_HOST, REDIS_PORT or localhost:6379')
|
|
25
24
|
.option('-t, --timeout <milliseconds>', 'ping period & timeout')
|
|
26
25
|
.option('-m, --metric <type>', 'show metric <number> 1:traffic, 2:echo')
|
|
27
26
|
.option('-s, --show-message <none|message>', 'show receive message. ')
|
|
28
27
|
.option('-f, --file-logger', 'write log files.')
|
|
29
|
-
.option('-a, --
|
|
28
|
+
.option('-a, --attach-services [list...]', 'one or multiple service module names: -a service1 service2')
|
|
30
29
|
.option('-o, --show-options', 'show server init options.')
|
|
31
30
|
.parse(process.argv)
|
|
32
31
|
|
|
@@ -70,8 +69,6 @@ if (options.authFile) {
|
|
|
70
69
|
authManager = new BohoAuth( new FileKeyProvider(authFilePath) )
|
|
71
70
|
} else if (options.authParam) {
|
|
72
71
|
authManager = new BohoAuth( new StringKeyProvider(options.authParam) )
|
|
73
|
-
} else if (options.authEnv) {
|
|
74
|
-
authManager = new BohoAuth( new StringKeyProvider(options.authEnv) )
|
|
75
72
|
} else if (options.authRedis) {
|
|
76
73
|
console.log("auth data origin: redis")
|
|
77
74
|
// console.log('####### default redis server url: redis://localhost:6379 ' )
|
|
@@ -87,26 +84,29 @@ if (options.authFile) {
|
|
|
87
84
|
|
|
88
85
|
const server = new Server( privateServerOptions , authManager);
|
|
89
86
|
|
|
90
|
-
if (options.
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
87
|
+
if (options.attachServices && options.attachServices.length > 0) {
|
|
88
|
+
let attachServices = options.attachServices
|
|
89
|
+
if (attachServices.includes('reply')){
|
|
90
|
+
server.attach('reply', replyService)
|
|
91
|
+
}
|
|
92
|
+
if (attachServices.includes('sudo')){
|
|
93
|
+
server.attach('sudo', sudoService)
|
|
94
|
+
}
|
|
95
|
+
if (attachServices.includes('redis')){
|
|
96
96
|
if(!redisClient){
|
|
97
97
|
redisClient = createClient();
|
|
98
98
|
redisClient.on('error', (err) => console.log('Redis Client Error', err));
|
|
99
99
|
redisClient.connect();
|
|
100
100
|
}
|
|
101
|
-
server.
|
|
101
|
+
server.attach('redis', new RedisService(redisClient))
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
console.log('registed service names', server.serviceNames)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (options.showOptions) {
|
|
107
107
|
console.log('global ServerOptions:', serverOption)
|
|
108
108
|
console.log('private ServerOptions:', privateServerOptions)
|
|
109
|
-
console.log('server
|
|
109
|
+
console.log('server serviceNames:', server.serviceNames)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
setTimeout(()=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal-cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "IOSignal server and client CLI program.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"boxen": "8.0.1",
|
|
22
22
|
"chalk": "5.6.2",
|
|
23
23
|
"commander": "13.1.0",
|
|
24
|
-
"iosignal": "^4.
|
|
24
|
+
"iosignal": "^4.8.0",
|
|
25
25
|
"redis": "4.7.1"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
package/auth_file.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
["sampleid","samplekey","sample_cid",0],
|
|
3
|
-
["id_max8","no_key_size_limit","communication_id",0],
|
|
4
|
-
["device1","device1_key","device1_cid",0],
|
|
5
|
-
["device2","device2_key","device2_cid",0],
|
|
6
|
-
["uno","uno","uno",1],
|
|
7
|
-
["go","go","go",2],
|
|
8
|
-
["bro","bro","bro",3],
|
|
9
|
-
["admin","admin","admin",255],
|
|
10
|
-
["adminb","adminb","adminb",255]
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
|