iosignal 1.3.2 → 1.4.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/dist/iosignal.cjs +1 -1
- package/dist/iosignal.esm.js +2 -2
- package/dist/iosignal.esm.js.map +1 -1
- package/dist/iosignal.min.js +2 -2
- package/dist/iosignal.min.js.map +1 -1
- package/package.json +8 -3
- package/src/client/IOCore.js +1 -1
- package/src/common/payload.js +7 -1
- package/src/common/quotaTable.js +7 -0
- package/src/server/Manager.js +18 -2
- package/src/server/ServerRemoteCore.js +5 -5
- package/test-signal-payloadType/signalPack.js +34 -0
- package/test-signal-payloadType/signaling.js +61 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "iosignal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/iosignal.cjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"boho": "^0.8.2",
|
|
38
38
|
"commander": "^9.5.0",
|
|
39
39
|
"eventemitter3": "^5.0.1",
|
|
40
|
-
"meta-buffer-pack": "^1.
|
|
40
|
+
"meta-buffer-pack": "^1.4.0",
|
|
41
41
|
"ws": "^8.16.0"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
@@ -50,6 +50,11 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://iosignal.net",
|
|
52
52
|
"keywords": [
|
|
53
|
-
"io",
|
|
53
|
+
"io",
|
|
54
|
+
"pubsub",
|
|
55
|
+
"arduino",
|
|
56
|
+
"iot",
|
|
57
|
+
"auth",
|
|
58
|
+
"signal"
|
|
54
59
|
]
|
|
55
60
|
}
|
package/src/client/IOCore.js
CHANGED
|
@@ -346,7 +346,7 @@ export class IOCore extends EventEmitter {
|
|
|
346
346
|
break;
|
|
347
347
|
|
|
348
348
|
case PAYLOAD_TYPE.MBA:
|
|
349
|
-
let mbaObject = MBP.unpack(
|
|
349
|
+
let mbaObject = MBP.unpack(payloadBuffer)
|
|
350
350
|
if (tag.indexOf('@') === 0) this.emit('@', ...mbaObject.args, tag)
|
|
351
351
|
if (tag !== '@') this.emit(tag, ...mbaObject.args, tag)
|
|
352
352
|
break;
|
package/src/common/payload.js
CHANGED
|
@@ -17,12 +17,13 @@ export function getSignalPack( tag, ...args ){
|
|
|
17
17
|
MBP.MB('#payloadType', '8', payload.type )
|
|
18
18
|
)
|
|
19
19
|
}else if( payload.type == PAYLOAD_TYPE.MBA ){
|
|
20
|
+
let mbaBuffer = MBP.pack( MBP.MBA(...args))
|
|
20
21
|
sigPack = MBP.pack(
|
|
21
22
|
MBP.MB('#MsgType','8', IOMsg.SIGNAL) ,
|
|
22
23
|
MBP.MB('#tagLen','8', tagEncoded.byteLength),
|
|
23
24
|
MBP.MB('#tag', tagEncoded),
|
|
24
25
|
MBP.MB('#payloadType', '8', payload.type ),
|
|
25
|
-
MBP.
|
|
26
|
+
MBP.MB('#mbaBuffer', mbaBuffer )
|
|
26
27
|
)
|
|
27
28
|
}else {
|
|
28
29
|
sigPack = MBP.pack(
|
|
@@ -74,4 +75,9 @@ export function parsePayload( args){
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
return { type: type, buffer: pack }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function getPayloadFromSignalPack( signalPack ){
|
|
81
|
+
let tagLen = signalPack.readUint8(1)
|
|
82
|
+
return signalPack.subarray(3 + tagLen)
|
|
77
83
|
}
|
package/src/common/quotaTable.js
CHANGED
|
@@ -50,6 +50,13 @@ export let quotaTable = {
|
|
|
50
50
|
|
|
51
51
|
// you can add your custom quota level.
|
|
52
52
|
|
|
53
|
+
// Remote service node
|
|
54
|
+
// High Quota, No root permission.
|
|
55
|
+
200: {
|
|
56
|
+
signalSize: 1048576 * 20,
|
|
57
|
+
publishCounter: 10000,
|
|
58
|
+
trafficRate: 1048576 * 100
|
|
59
|
+
},
|
|
53
60
|
// super admin or root user.
|
|
54
61
|
// to monitor, metric, sudo command, db acess
|
|
55
62
|
255: {
|
package/src/server/Manager.js
CHANGED
|
@@ -141,7 +141,7 @@ export class Manager{
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
// unix wall like
|
|
145
145
|
serverSignal(obj) {
|
|
146
146
|
let sigPack = MBP.pack(
|
|
147
147
|
MBP.MB('#MsgType', '8', IOMsg.SERVER_SIGNAL),
|
|
@@ -188,6 +188,21 @@ export class Manager{
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
serverSignalTo( tag, ...args ){
|
|
192
|
+
let cid = tag.split('@')[0]
|
|
193
|
+
let topic = tag.split('@')[1]
|
|
194
|
+
let sigPack = getSignalPack( '@'+topic, ...args )
|
|
195
|
+
// console.log('tag split', cid )
|
|
196
|
+
if (cid && this.cid2remote.has(cid)) {
|
|
197
|
+
let targetRemote = this.cid2remote.get(cid)
|
|
198
|
+
console.log('target', targetRemote.state ,targetRemote.cid )
|
|
199
|
+
targetRemote.send_enc_mode(sigPack)
|
|
200
|
+
return
|
|
201
|
+
}else{
|
|
202
|
+
return "no cid"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
191
206
|
sender(tag, remote, message) {
|
|
192
207
|
if(serverOption.memberOnly && !remote.boho.isAuthorized){
|
|
193
208
|
// console.log("## MemberOnly, reject unAuthorized remote." )
|
|
@@ -200,7 +215,7 @@ export class Manager{
|
|
|
200
215
|
|
|
201
216
|
let cidIndex = tag.indexOf('@');
|
|
202
217
|
if (cidIndex === 0) {
|
|
203
|
-
// ** CID_PUB
|
|
218
|
+
// ** CID_PUB multi-cast
|
|
204
219
|
// [cid_pub] @topic , @$retainTopic
|
|
205
220
|
// modify signalpack with cid_appneded tag.
|
|
206
221
|
tag = remote.cid + tag;
|
|
@@ -214,6 +229,7 @@ export class Manager{
|
|
|
214
229
|
if (this.cid2remote.has(targetCId)) {
|
|
215
230
|
//rm cid from tag.
|
|
216
231
|
let ommitCIdTag = '@' + tag.split('@')[1]
|
|
232
|
+
// console.log('uni-cast tag change from', tag, 'to' , ommitCIdTag )
|
|
217
233
|
message = this.getNewSignalTagMessage(message, ommitCIdTag)
|
|
218
234
|
// console.log(`origin tag: ${tag} omitTag: ${this.getSignalTag(message)}`)
|
|
219
235
|
this.cid2remote.get(targetCId).send_enc_mode(message)
|
|
@@ -73,19 +73,19 @@ export class ServerRemoteCore {
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
showMessageLog(message, isBinary) {
|
|
76
|
-
let from = this.boho.isAuthorized ? `
|
|
76
|
+
let from = this.boho.isAuthorized ? `did: ${this.did} ${this.cid}@` : `${this.cid}@`
|
|
77
77
|
if (isBinary) {
|
|
78
78
|
let msgTypeName = IOMsg[message[0]]
|
|
79
79
|
if (!msgTypeName) msgTypeName = BohoMsg[message[0]]
|
|
80
|
-
|
|
80
|
+
msgTypeName =' [' + msgTypeName + ']';
|
|
81
81
|
if (message.byteLength > 40) {
|
|
82
|
-
console.log(
|
|
82
|
+
console.log(from + msgTypeName + ' LEN:', message.length);
|
|
83
83
|
} else {
|
|
84
|
-
console.log(
|
|
84
|
+
console.log(from + msgTypeName , message);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
} else {
|
|
88
|
-
console.log(from + '[TEXT
|
|
88
|
+
console.log(from + ' [TEXT] %s', message);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parsePayload, getSignalPack, getPayloadFromSignalPack, PAYLOAD_TYPE, MBP } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const type0 = []
|
|
4
|
+
const type1t = ['a1']
|
|
5
|
+
const type1n = [11]
|
|
6
|
+
const type2 = [new Uint8Array(5)]
|
|
7
|
+
const type3 = [{ name: 'type3' }]
|
|
8
|
+
const type4a = ['a2', 222]
|
|
9
|
+
const type4b = [{ name: 'a3' }, 333]
|
|
10
|
+
const type5 = [{ a: 1 }, Buffer.from('BBBBBB')]
|
|
11
|
+
|
|
12
|
+
// zero or one argument support: 0:EMPTY, 1:TEXT , 2:BINARY signal payload type
|
|
13
|
+
console.log(PAYLOAD_TYPE[parsePayload(type0).type], type0) // empty
|
|
14
|
+
console.log(PAYLOAD_TYPE[parsePayload(type1t).type], type1t) // text
|
|
15
|
+
console.log(PAYLOAD_TYPE[parsePayload(type1n).type], type1n) // number text. there is no Number type of signalPaylod.
|
|
16
|
+
console.log(PAYLOAD_TYPE[parsePayload(type2).type], type2) // binary.
|
|
17
|
+
|
|
18
|
+
// over two arguments support: 3:Object, 4:MJSON and 5:MBA can hold Number item.
|
|
19
|
+
console.log(PAYLOAD_TYPE[parsePayload(type3).type], type3) // Object
|
|
20
|
+
console.log(PAYLOAD_TYPE[parsePayload(type4a).type], type4a) // MJSON
|
|
21
|
+
console.log(PAYLOAD_TYPE[parsePayload(type4b).type], type4b) // MJSON
|
|
22
|
+
console.log(PAYLOAD_TYPE[parsePayload(type5).type], type5) // MBA
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
let signalTag = 'channel'
|
|
26
|
+
let signalPack = getSignalPack( signalTag, ...type5)
|
|
27
|
+
console.log('signalPack', signalPack)
|
|
28
|
+
|
|
29
|
+
let payloadBuffer = getPayloadFromSignalPack(signalPack)
|
|
30
|
+
let unpack = MBP.unpack(payloadBuffer)
|
|
31
|
+
console.log(unpack)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IO, Server} from 'iosignal'
|
|
2
|
+
|
|
3
|
+
let url = 'ws://localhost:5555'
|
|
4
|
+
let server = new Server({
|
|
5
|
+
port: 5555
|
|
6
|
+
// ,showMessage: 'message'
|
|
7
|
+
})
|
|
8
|
+
let done = false;
|
|
9
|
+
|
|
10
|
+
let tx = new IO(url)
|
|
11
|
+
tx.on('ready', () => {
|
|
12
|
+
console.log('tx ready', tx.cid)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let rx = new IO(url)
|
|
17
|
+
rx.on('ready', () => {
|
|
18
|
+
console.log('rx ready', rx.cid)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
rx.listen('@', (...args) => {
|
|
22
|
+
console.log('uni-cast rxi', args)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
rx.listen('channel', (...args) => {
|
|
26
|
+
console.log('multi-cast rxi', args)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function sendSignals() {
|
|
30
|
+
// uni-casting: tag is receiver CID@.
|
|
31
|
+
let tag = rx.cid + '@topic'
|
|
32
|
+
tx.signal(tag, ...arg1)
|
|
33
|
+
tx.signal(tag, ...arg2)
|
|
34
|
+
tx.signal(tag, ...arg3)
|
|
35
|
+
tx.signal(tag, ...arg4)
|
|
36
|
+
tx.signal(tag, ...arg5)
|
|
37
|
+
|
|
38
|
+
// multi-casting: tag is channel name.
|
|
39
|
+
tag = 'channel'
|
|
40
|
+
tx.signal(tag, ...arg1)
|
|
41
|
+
tx.signal(tag, ...arg2)
|
|
42
|
+
tx.signal(tag, ...arg3)
|
|
43
|
+
tx.signal(tag, ...arg4)
|
|
44
|
+
tx.signal(tag, ...arg5)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const arg1 = ['a1']
|
|
49
|
+
const arg2 = ['a2', 222]
|
|
50
|
+
const arg3 = [{ name: 'a3' }, 333]
|
|
51
|
+
const arg4 = [{a:1}, Buffer.from('KKKKK')]
|
|
52
|
+
const arg5 = [new Uint8Array(20)]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
sendSignals();
|
|
57
|
+
}, 1000)
|
|
58
|
+
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
process.exit()
|
|
61
|
+
}, 2000)
|