iosignal 4.6.1 → 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/.vscode/settings.json +1 -1
- package/README.md +30 -7
- package/dist/io.d.ts +7 -13
- package/dist/io.js +4 -4
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +3 -3
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +74 -110
- package/dist/types/client/IOCore.d.ts +7 -13
- package/dist/types/common/constants.d.ts +2 -12
- package/index.js +4 -4
- package/package.json +1 -1
- package/src/auth/key_providers/RedisKeyProvider.js +2 -2
- package/src/client/IOCore.js +20 -47
- package/src/common/constants.js +5 -15
- package/src/server/Manager.js +1 -1
- package/src/server/Remote.js +1 -0
- package/src/server/RemoteCore.js +3 -3
- package/src/server/Server.js +27 -27
- package/src/{api/RedisAPI.js → services/RedisService.js} +6 -6
- package/src/{api/api_reply.js → services/replyService.js} +5 -5
- package/src/{api/api_sudo.js → services/sudoService.js} +3 -3
- package/tsconfig.json +1 -1
- /package/src/{api/api_constant.js → services/constant.js} +0 -0
package/dist/iosignal.js
CHANGED
|
@@ -13,7 +13,7 @@ import require$$2, { networkInterfaces } from 'os';
|
|
|
13
13
|
import require$$0$1 from 'buffer';
|
|
14
14
|
import { memoryUsage } from 'process';
|
|
15
15
|
|
|
16
|
-
var version$1 = "4.
|
|
16
|
+
var version$1 = "4.8.0";
|
|
17
17
|
var pkg = {
|
|
18
18
|
version: version$1};
|
|
19
19
|
|
|
@@ -497,7 +497,7 @@ for (let c in PAYLOAD_TYPE) { PAYLOAD_TYPE[PAYLOAD_TYPE[c]] = c; }
|
|
|
497
497
|
* @property {number} SET
|
|
498
498
|
* @property {number} RESPONSE_CODE
|
|
499
499
|
* @property {number} RESPONSE_MBP
|
|
500
|
-
* @property {number}
|
|
500
|
+
* @property {number} CALL
|
|
501
501
|
* @property {number} RESPONSE
|
|
502
502
|
* @property {number} FLOW_MODE
|
|
503
503
|
* @property {number} WAIT
|
|
@@ -562,11 +562,10 @@ let IOMsg = {
|
|
|
562
562
|
|
|
563
563
|
//..
|
|
564
564
|
SET: 0xDB, //
|
|
565
|
-
RESPONSE_CODE: 0xDC,
|
|
565
|
+
// RESPONSE_CODE: 0xDC,
|
|
566
566
|
RESPONSE_MBP: 0xDD,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
RESPONSE: 0xDF,
|
|
567
|
+
CALL: 0xDE, // rpc call
|
|
568
|
+
// RESPONSE: 0xDF,
|
|
570
569
|
// ~DF
|
|
571
570
|
|
|
572
571
|
|
|
@@ -584,22 +583,13 @@ let IOMsg = {
|
|
|
584
583
|
for (let c in IOMsg) { IOMsg[IOMsg[c]] = c; }
|
|
585
584
|
// console.log( IOMsg );
|
|
586
585
|
|
|
587
|
-
/**
|
|
588
|
-
* @typedef {object} API_TYPE
|
|
589
|
-
* @property {string} REQUEST_RESPONSE
|
|
590
|
-
* @property {string} ONE_WAY
|
|
591
|
-
*/
|
|
592
|
-
const API_TYPE = {
|
|
593
|
-
'REQUEST_RESPONSE': 'requet_response',
|
|
594
|
-
'ONE_WAY': 'one_way'
|
|
595
|
-
};
|
|
596
586
|
|
|
597
587
|
/**
|
|
598
588
|
* @typedef {object} STATUS
|
|
599
589
|
* @property {number} OK
|
|
600
590
|
* @property {number} ERROR
|
|
601
591
|
*/
|
|
602
|
-
//
|
|
592
|
+
// service response status code
|
|
603
593
|
const STATUS$1 = {
|
|
604
594
|
OK: 0,
|
|
605
595
|
//0~127: success
|
|
@@ -1225,7 +1215,7 @@ class IOCore extends EventEmitter {
|
|
|
1225
1215
|
|
|
1226
1216
|
// **IMPORTANT** change state before subscribe.
|
|
1227
1217
|
this.stateChange('ready', 'cid_ready');
|
|
1228
|
-
this.
|
|
1218
|
+
this.subscribe_channels();
|
|
1229
1219
|
break;
|
|
1230
1220
|
|
|
1231
1221
|
case IOMsg.QUOTA_LEVEL:
|
|
@@ -1494,6 +1484,7 @@ class IOCore extends EventEmitter {
|
|
|
1494
1484
|
console.log('## your maximum signalSize(bytes) is:', this.quota.signalSize);
|
|
1495
1485
|
return
|
|
1496
1486
|
}
|
|
1487
|
+
// console.log(`C->[${IOMsg[ data[0]]}]`)
|
|
1497
1488
|
this.socket_send(data);
|
|
1498
1489
|
}
|
|
1499
1490
|
|
|
@@ -1662,7 +1653,7 @@ class IOCore extends EventEmitter {
|
|
|
1662
1653
|
if (!storeName || args.length == 0) {
|
|
1663
1654
|
return Promise.reject(new Error('set need storeName and value)'))
|
|
1664
1655
|
}
|
|
1665
|
-
return this.
|
|
1656
|
+
return this.call('store', 'set', storeName, ...args)
|
|
1666
1657
|
}
|
|
1667
1658
|
|
|
1668
1659
|
/**
|
|
@@ -1674,26 +1665,26 @@ class IOCore extends EventEmitter {
|
|
|
1674
1665
|
if (!storeName) {
|
|
1675
1666
|
return Promise.reject(new Error('store get need storeName)'))
|
|
1676
1667
|
}
|
|
1677
|
-
let pack = await this.
|
|
1668
|
+
let pack = await this.call('store', 'get', storeName);
|
|
1678
1669
|
let { $ } = M$1.unpack(pack.body);
|
|
1679
1670
|
return $
|
|
1680
1671
|
}
|
|
1681
1672
|
|
|
1682
1673
|
|
|
1683
1674
|
/**
|
|
1684
|
-
* Sends a request to a target and topic.(remote
|
|
1685
|
-
* @param {string} target - The target(
|
|
1686
|
-
* @param {string} topic - The topic(
|
|
1675
|
+
* Sends a request to a target and topic.(remote service call)
|
|
1676
|
+
* @param {string} target - The target(service name) of the request.
|
|
1677
|
+
* @param {string} topic - The topic(service function name) of the request.
|
|
1687
1678
|
* @param {...any} args - Optional arguments for the request.
|
|
1688
1679
|
* @returns {Promise<any>}
|
|
1689
1680
|
*/
|
|
1690
|
-
|
|
1681
|
+
call(target, topic, ...args) {
|
|
1691
1682
|
if (!target || !topic)
|
|
1692
1683
|
return Promise.reject(new Error('request need target and topic)'))
|
|
1693
1684
|
let sigPack;
|
|
1694
1685
|
if (args.length > 0) {
|
|
1695
1686
|
sigPack = M$1.pack(
|
|
1696
|
-
M$1.MB('#MsgType', '8', IOMsg.
|
|
1687
|
+
M$1.MB('#MsgType', '8', IOMsg.CALL),
|
|
1697
1688
|
M$1.MB('mid', '16', ++this.mid),
|
|
1698
1689
|
M$1.MB('target', target),
|
|
1699
1690
|
M$1.MB('topic', topic),
|
|
@@ -1701,7 +1692,7 @@ class IOCore extends EventEmitter {
|
|
|
1701
1692
|
);
|
|
1702
1693
|
} else {
|
|
1703
1694
|
sigPack = M$1.pack(
|
|
1704
|
-
M$1.MB('#MsgType', '8', IOMsg.
|
|
1695
|
+
M$1.MB('#MsgType', '8', IOMsg.CALL),
|
|
1705
1696
|
M$1.MB('mid', '16', ++this.mid),
|
|
1706
1697
|
M$1.MB('target', target),
|
|
1707
1698
|
M$1.MB('topic', topic)
|
|
@@ -1720,14 +1711,6 @@ class IOCore extends EventEmitter {
|
|
|
1720
1711
|
subscribe(tag) {
|
|
1721
1712
|
if (typeof tag !== 'string') throw TypeError('tag should be string.')
|
|
1722
1713
|
if (tag.length > SIZE_LIMIT.TAG_LEN1) throw TypeError('please check tag string length limit:' + SIZE_LIMIT.TAG_LEN1)
|
|
1723
|
-
if (this.state !== STATE.READY) return
|
|
1724
|
-
|
|
1725
|
-
// subscribe 사용시, 사용 'ready' 이벤트시 메뉴얼 등록되므로 여기에 등록하면 2중 호출된다.
|
|
1726
|
-
// 즉, channels 등록은 listen 같은 자동화 구독시만 사용.
|
|
1727
|
-
// let tagList = tag.split(',')
|
|
1728
|
-
// tagList.forEach(tag => {
|
|
1729
|
-
// this.channels.add(tag)
|
|
1730
|
-
// })
|
|
1731
1714
|
|
|
1732
1715
|
try {
|
|
1733
1716
|
let tagEncoded = encoder$1.encode(tag);
|
|
@@ -1737,47 +1720,27 @@ class IOCore extends EventEmitter {
|
|
|
1737
1720
|
M$1.NB('8', tagEncoded.byteLength),
|
|
1738
1721
|
tagEncoded]));
|
|
1739
1722
|
} catch (error) { }
|
|
1723
|
+
|
|
1740
1724
|
}
|
|
1741
1725
|
|
|
1726
|
+
|
|
1742
1727
|
/**
|
|
1743
|
-
* Subscribes
|
|
1744
|
-
*
|
|
1745
|
-
* @returns {Promise<any>}
|
|
1746
|
-
* @throws {TypeError} If tag is not a string or exceeds length limit.
|
|
1728
|
+
* Subscribes stored channels.
|
|
1729
|
+
* called client state become 'ready'
|
|
1747
1730
|
*/
|
|
1748
|
-
|
|
1749
|
-
if (
|
|
1750
|
-
if (
|
|
1751
|
-
|
|
1752
|
-
if (this.state !== STATE.READY) {
|
|
1753
|
-
return Promise.reject('subscribe_promise:: connection is not ready')
|
|
1754
|
-
}
|
|
1731
|
+
subscribe_channels() {
|
|
1732
|
+
if (this.state !== STATE.READY) return
|
|
1733
|
+
if (this.channels.size == 0) return
|
|
1734
|
+
let tag = Array.from(this.channels).join(',');
|
|
1755
1735
|
|
|
1756
1736
|
try {
|
|
1757
1737
|
let tagEncoded = encoder$1.encode(tag);
|
|
1758
1738
|
this.send_enc_mode(
|
|
1759
1739
|
Buffer$1.concat([
|
|
1760
|
-
M$1.NB('8', IOMsg.
|
|
1761
|
-
M$1.NB('
|
|
1762
|
-
M$1.NB('16', tagEncoded.byteLength),
|
|
1740
|
+
M$1.NB('8', IOMsg.SUBSCRIBE),
|
|
1741
|
+
M$1.NB('8', tagEncoded.byteLength),
|
|
1763
1742
|
tagEncoded]));
|
|
1764
|
-
return this.setMsgPromise(this.mid)
|
|
1765
1743
|
} catch (error) { }
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
/**
|
|
1769
|
-
* Subscribes to channels stored in memory (local cache).
|
|
1770
|
-
*/
|
|
1771
|
-
subscribe_memory_channels() { //local cache . auto_resubscribe
|
|
1772
|
-
if (this.channels.size == 0) return
|
|
1773
|
-
let chList = Array.from(this.channels).join(',');
|
|
1774
|
-
|
|
1775
|
-
this.subscribe_promise(chList)
|
|
1776
|
-
.then((res) => {
|
|
1777
|
-
// console.log('>> SUBSCRIBE_REQ result', res ) // return code == map.size
|
|
1778
|
-
}).catch((e) => {
|
|
1779
|
-
console.log('>> SUBSCRIBE FAIL:', e);
|
|
1780
|
-
});
|
|
1781
1744
|
|
|
1782
1745
|
}
|
|
1783
1746
|
|
|
@@ -7938,15 +7901,15 @@ class RemoteCore {
|
|
|
7938
7901
|
break;
|
|
7939
7902
|
|
|
7940
7903
|
|
|
7941
|
-
case IOMsg.
|
|
7904
|
+
case IOMsg.CALL: //service request
|
|
7942
7905
|
try {
|
|
7943
7906
|
let req = M$1.unpack(message);
|
|
7944
7907
|
if (req) {
|
|
7945
7908
|
if (!req.target || !req.topic) return
|
|
7946
|
-
if (this.manager.server.
|
|
7909
|
+
if (this.manager.server.serviceNames.has(req.target)) {
|
|
7947
7910
|
this.manager.server.emit(req.target, this, req);
|
|
7948
7911
|
} else {
|
|
7949
|
-
// console.log('UnKnown
|
|
7912
|
+
// console.log('UnKnown Service call: ', req.target)
|
|
7950
7913
|
}
|
|
7951
7914
|
}
|
|
7952
7915
|
} catch (e) {
|
|
@@ -8343,6 +8306,7 @@ class Remote extends RemoteCore {
|
|
|
8343
8306
|
|
|
8344
8307
|
// node.js server side remote.
|
|
8345
8308
|
send(message, isBinary) {
|
|
8309
|
+
// console.log(`<-S [${IOMsg[ message[0]]}]`)
|
|
8346
8310
|
this.manager.txBytes += message.byteLength;
|
|
8347
8311
|
this.socket.txCounter++;
|
|
8348
8312
|
if (this.socketType === 'websocket') {
|
|
@@ -8657,7 +8621,7 @@ class Manager {
|
|
|
8657
8621
|
}
|
|
8658
8622
|
|
|
8659
8623
|
|
|
8660
|
-
if (remote.uid && this.server.
|
|
8624
|
+
if (remote.uid && this.server.serviceNames.has('account')) {
|
|
8661
8625
|
let req = { topic: 'detachUserRemote' };
|
|
8662
8626
|
req.args = ['caller:manager.removeRemote'];
|
|
8663
8627
|
this.server.emit('account', remote, req);
|
|
@@ -8989,7 +8953,7 @@ class Server extends require$$0$3 {
|
|
|
8989
8953
|
|
|
8990
8954
|
constructor(options, authManager) {
|
|
8991
8955
|
super();
|
|
8992
|
-
this.
|
|
8956
|
+
this.serviceNames = new Set();
|
|
8993
8957
|
this.wss = {};
|
|
8994
8958
|
this.port = null;
|
|
8995
8959
|
this.congPort = null;
|
|
@@ -9110,63 +9074,63 @@ class Server extends require$$0$3 {
|
|
|
9110
9074
|
}
|
|
9111
9075
|
|
|
9112
9076
|
/**
|
|
9113
|
-
*
|
|
9114
|
-
* target:
|
|
9115
|
-
*
|
|
9077
|
+
* RPC service register.
|
|
9078
|
+
* target: service_name <string>
|
|
9079
|
+
* service: service_module <function module|class instance>
|
|
9116
9080
|
* return this
|
|
9117
9081
|
*/
|
|
9118
|
-
|
|
9082
|
+
attach(target, service_module) {
|
|
9119
9083
|
|
|
9120
9084
|
if( typeof target !== 'string'){
|
|
9121
|
-
throw new Error(`
|
|
9085
|
+
throw new Error(`service( target ,service ) target name is not a string.`)
|
|
9122
9086
|
}
|
|
9123
|
-
if (!
|
|
9124
|
-
throw new Error(`
|
|
9087
|
+
if (!service_module.checkPermission || typeof service_module.checkPermission != 'function') {
|
|
9088
|
+
throw new Error(`Service ${target} : no checkPermission or not a function.`)
|
|
9125
9089
|
}
|
|
9126
|
-
if(!
|
|
9127
|
-
throw new Error(`
|
|
9090
|
+
if(!service_module.commands || !Array.isArray(service_module.commands) ){
|
|
9091
|
+
throw new Error(`Service ${target} : no commands or !Array.`)
|
|
9128
9092
|
}
|
|
9129
9093
|
|
|
9130
|
-
//
|
|
9131
|
-
if (
|
|
9094
|
+
// Service TYPE 1. single call() function.
|
|
9095
|
+
if ( service_module.call && typeof service_module.call == 'function' ) {
|
|
9132
9096
|
this.on(target, async (remote, req) => {
|
|
9133
9097
|
try {
|
|
9134
|
-
if (!
|
|
9098
|
+
if (!service_module.checkPermission(remote, req)) {
|
|
9135
9099
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
9136
9100
|
return
|
|
9137
9101
|
}
|
|
9138
|
-
if(
|
|
9139
|
-
// console.log('server
|
|
9140
|
-
await
|
|
9102
|
+
if( service_module.commands.includes( req.topic )){
|
|
9103
|
+
// console.log('server service_module req', req )
|
|
9104
|
+
await service_module.call(remote, req);
|
|
9141
9105
|
}else {
|
|
9142
9106
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9143
9107
|
}
|
|
9144
9108
|
} catch (error) {
|
|
9145
|
-
console.error(`Unhandled
|
|
9109
|
+
console.error(`Unhandled Service Error in target [${target}]:`, error);
|
|
9146
9110
|
remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
|
|
9147
9111
|
}
|
|
9148
9112
|
});
|
|
9149
9113
|
} else {
|
|
9150
|
-
//
|
|
9114
|
+
// Service TYPE 2. multiple functions.
|
|
9151
9115
|
this.on(target, async (remote, req) => {
|
|
9152
9116
|
try {
|
|
9153
|
-
if (!
|
|
9117
|
+
if (!service_module.checkPermission(remote, req)) {
|
|
9154
9118
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
9155
9119
|
return
|
|
9156
9120
|
}
|
|
9157
|
-
if(
|
|
9158
|
-
await
|
|
9121
|
+
if( service_module.commands.includes( req.topic )){
|
|
9122
|
+
await service_module[req.topic](remote, req);
|
|
9159
9123
|
}else {
|
|
9160
9124
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9161
9125
|
}
|
|
9162
9126
|
} catch (error) {
|
|
9163
|
-
console.error(`Unhandled
|
|
9127
|
+
console.error(`Unhandled Service Error in target [${target}]:`, error);
|
|
9164
9128
|
remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
|
|
9165
9129
|
}
|
|
9166
9130
|
});
|
|
9167
9131
|
}
|
|
9168
|
-
this.
|
|
9169
|
-
// console.log(`[
|
|
9132
|
+
this.serviceNames.add(target);
|
|
9133
|
+
// console.log(`[Service attached: ${target} ] accept commands: ${service_module.commands}`)
|
|
9170
9134
|
return this
|
|
9171
9135
|
}
|
|
9172
9136
|
|
|
@@ -9176,8 +9140,8 @@ class Server extends require$$0$3 {
|
|
|
9176
9140
|
this.manager.close();
|
|
9177
9141
|
}
|
|
9178
9142
|
|
|
9179
|
-
this.
|
|
9180
|
-
this.
|
|
9143
|
+
this.serviceNames.forEach(v => this.removeAllListeners(v));
|
|
9144
|
+
this.serviceNames.clear();
|
|
9181
9145
|
|
|
9182
9146
|
let serverCount = 0;
|
|
9183
9147
|
if (this.wss) serverCount++;
|
|
@@ -9486,7 +9450,7 @@ class RedisKeyProvider {
|
|
|
9486
9450
|
}
|
|
9487
9451
|
}
|
|
9488
9452
|
|
|
9489
|
-
//
|
|
9453
|
+
//sudoService call
|
|
9490
9454
|
async getAuthIdList() {
|
|
9491
9455
|
let result = await this.redis.keys(DEVICE_PREFIX + '*');
|
|
9492
9456
|
result = result.map(v => {
|
|
@@ -9501,7 +9465,7 @@ class RedisKeyProvider {
|
|
|
9501
9465
|
return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
|
|
9502
9466
|
}
|
|
9503
9467
|
|
|
9504
|
-
//
|
|
9468
|
+
//sudoService call
|
|
9505
9469
|
async delAuth(id) {
|
|
9506
9470
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
9507
9471
|
}
|
|
@@ -9573,7 +9537,7 @@ function checkPermission$1(remote) {
|
|
|
9573
9537
|
}
|
|
9574
9538
|
|
|
9575
9539
|
/**
|
|
9576
|
-
* client api call example: await io.
|
|
9540
|
+
* client api call example: await io.call('reply','echo','hello')
|
|
9577
9541
|
*/
|
|
9578
9542
|
async function echo(remote, req) {
|
|
9579
9543
|
if (!req.args)
|
|
@@ -9583,7 +9547,7 @@ async function echo(remote, req) {
|
|
|
9583
9547
|
}
|
|
9584
9548
|
|
|
9585
9549
|
/**
|
|
9586
|
-
* client api call example: await io.
|
|
9550
|
+
* client api call example: await io.call('reply','date')
|
|
9587
9551
|
*/
|
|
9588
9552
|
async function date(remote, req) {
|
|
9589
9553
|
let r = new Date().toUTCString();
|
|
@@ -9591,14 +9555,14 @@ async function date(remote, req) {
|
|
|
9591
9555
|
}
|
|
9592
9556
|
|
|
9593
9557
|
/**
|
|
9594
|
-
* client api call example: await io.
|
|
9558
|
+
* client api call example: await io.call('reply','unixtime')
|
|
9595
9559
|
*/
|
|
9596
9560
|
async function unixtime(remote, req) {
|
|
9597
9561
|
let r = Math.floor(Date.now() / 1000);
|
|
9598
9562
|
remote.response(req.mid, STATUS.OK, r);
|
|
9599
9563
|
}
|
|
9600
9564
|
|
|
9601
|
-
var
|
|
9565
|
+
var replyService = /*#__PURE__*/Object.freeze({
|
|
9602
9566
|
__proto__: null,
|
|
9603
9567
|
checkPermission: checkPermission$1,
|
|
9604
9568
|
commands: commands$1,
|
|
@@ -9621,7 +9585,7 @@ function checkPermission(remote) {
|
|
|
9621
9585
|
return (remote.level >= MIN_LEVEL$1) ? true : false;
|
|
9622
9586
|
}
|
|
9623
9587
|
|
|
9624
|
-
async function
|
|
9588
|
+
async function call(remote, req) {
|
|
9625
9589
|
let result;
|
|
9626
9590
|
let status = 0;
|
|
9627
9591
|
try {
|
|
@@ -9677,7 +9641,7 @@ async function request(remote, req) {
|
|
|
9677
9641
|
}
|
|
9678
9642
|
} else {
|
|
9679
9643
|
status = STATUS.ERROR;
|
|
9680
|
-
result = "
|
|
9644
|
+
result = "service sudo: no such a cmd: " + cmd;
|
|
9681
9645
|
}
|
|
9682
9646
|
|
|
9683
9647
|
remote.response(req.mid, status, result);
|
|
@@ -9688,21 +9652,21 @@ async function request(remote, req) {
|
|
|
9688
9652
|
|
|
9689
9653
|
}
|
|
9690
9654
|
|
|
9691
|
-
var
|
|
9655
|
+
var sudoService = /*#__PURE__*/Object.freeze({
|
|
9692
9656
|
__proto__: null,
|
|
9657
|
+
call: call,
|
|
9693
9658
|
checkPermission: checkPermission,
|
|
9694
|
-
commands: commands
|
|
9695
|
-
request: request
|
|
9659
|
+
commands: commands
|
|
9696
9660
|
});
|
|
9697
9661
|
|
|
9698
9662
|
/**
|
|
9699
|
-
*
|
|
9663
|
+
* RedisService <IOSignal RPC Service>
|
|
9700
9664
|
*
|
|
9701
9665
|
* iosignal 클라이언트의 redis 질의 요청을 받으면,
|
|
9702
9666
|
* redisClient 로 연결된 redis-server 에게 질의 후 결과를 되돌려 준다.
|
|
9703
9667
|
*
|
|
9704
9668
|
* client ex:
|
|
9705
|
-
* await io.
|
|
9669
|
+
* await io.call('redis','hget','user:id' )
|
|
9706
9670
|
*
|
|
9707
9671
|
*/
|
|
9708
9672
|
|
|
@@ -9714,10 +9678,10 @@ const COMMANDS = [
|
|
|
9714
9678
|
'sMembers', 'exists', 'sRem', 'del', 'keys', 'save'
|
|
9715
9679
|
];
|
|
9716
9680
|
|
|
9717
|
-
class
|
|
9681
|
+
class RedisService {
|
|
9718
9682
|
constructor(redisClient, _minLevel) {
|
|
9719
9683
|
if (!redisClient) {
|
|
9720
|
-
throw new Error("
|
|
9684
|
+
throw new Error("RedisService constructor: no redisClient")
|
|
9721
9685
|
}
|
|
9722
9686
|
this.redisClient = redisClient;
|
|
9723
9687
|
this.minLevel = _minLevel ? _minLevel : MIN_LEVEL;
|
|
@@ -9728,7 +9692,7 @@ class RedisAPI {
|
|
|
9728
9692
|
return (remote.level >= this.minLevel) ? true : false;
|
|
9729
9693
|
}
|
|
9730
9694
|
|
|
9731
|
-
async
|
|
9695
|
+
async call(remote, req) {
|
|
9732
9696
|
let result;
|
|
9733
9697
|
try {
|
|
9734
9698
|
let cmd = req.topic;
|
|
@@ -9747,4 +9711,4 @@ class RedisAPI {
|
|
|
9747
9711
|
|
|
9748
9712
|
const version = pkg.version;
|
|
9749
9713
|
|
|
9750
|
-
export {
|
|
9714
|
+
export { tt as Boho, BohoAuth, CongRx, ENC_MODE, FileKeyProvider, FileLogger, IOWS as IO, IOCongSocket, IOMsg, M$1 as MBP, PAYLOAD_TYPE, RedisKeyProvider, RedisService, SIZE_LIMIT, STATE, STATUS$1 as STATUS, Server, StringKeyProvider, delay, getIPv4HexString, getLocalAddress, getPayloadFromSignalPack, getSignalPack, isPrivateIP, numberWithCommas, pack, parsePayload, replyService, serverOption, sudoService, version };
|
|
@@ -304,13 +304,13 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
304
304
|
*/
|
|
305
305
|
get(storeName: string): Promise<any>;
|
|
306
306
|
/**
|
|
307
|
-
* Sends a request to a target and topic.(remote
|
|
308
|
-
* @param {string} target - The target(
|
|
309
|
-
* @param {string} topic - The topic(
|
|
307
|
+
* Sends a request to a target and topic.(remote service call)
|
|
308
|
+
* @param {string} target - The target(service name) of the request.
|
|
309
|
+
* @param {string} topic - The topic(service function name) of the request.
|
|
310
310
|
* @param {...any} args - Optional arguments for the request.
|
|
311
311
|
* @returns {Promise<any>}
|
|
312
312
|
*/
|
|
313
|
-
|
|
313
|
+
call(target: string, topic: string, ...args: any[]): Promise<any>;
|
|
314
314
|
/**
|
|
315
315
|
* Subscribes to a channel or channels.
|
|
316
316
|
* @param {string} tag - The tag(s) of the channel(s) to subscribe to (comma-separated).
|
|
@@ -318,16 +318,10 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
318
318
|
*/
|
|
319
319
|
subscribe(tag: string): void;
|
|
320
320
|
/**
|
|
321
|
-
* Subscribes
|
|
322
|
-
*
|
|
323
|
-
* @returns {Promise<any>}
|
|
324
|
-
* @throws {TypeError} If tag is not a string or exceeds length limit.
|
|
325
|
-
*/
|
|
326
|
-
subscribe_promise(tag: string): Promise<any>;
|
|
327
|
-
/**
|
|
328
|
-
* Subscribes to channels stored in memory (local cache).
|
|
321
|
+
* Subscribes stored channels.
|
|
322
|
+
* called client state become 'ready'
|
|
329
323
|
*/
|
|
330
|
-
|
|
324
|
+
subscribe_channels(): void;
|
|
331
325
|
/**
|
|
332
326
|
* Unsubscribes from a channel or channels.
|
|
333
327
|
* @param {string} [tag=""] - The tag(s) of the channel(s) to unsubscribe from (comma-separated). If empty, unsubscribes from all.
|
|
@@ -97,7 +97,7 @@ export type IOMsg = {
|
|
|
97
97
|
SET: number;
|
|
98
98
|
RESPONSE_CODE: number;
|
|
99
99
|
RESPONSE_MBP: number;
|
|
100
|
-
|
|
100
|
+
CALL: number;
|
|
101
101
|
RESPONSE: number;
|
|
102
102
|
FLOW_MODE: number;
|
|
103
103
|
WAIT: number;
|
|
@@ -132,10 +132,8 @@ export namespace IOMsg {
|
|
|
132
132
|
export let IAM: number;
|
|
133
133
|
export let IAM_RES: number;
|
|
134
134
|
export let SET: number;
|
|
135
|
-
export let RESPONSE_CODE: number;
|
|
136
135
|
export let RESPONSE_MBP: number;
|
|
137
|
-
export let
|
|
138
|
-
export let RESPONSE: number;
|
|
136
|
+
export let CALL: number;
|
|
139
137
|
export let FLOW_MODE: number;
|
|
140
138
|
export let WAIT: number;
|
|
141
139
|
export let RESUME: number;
|
|
@@ -143,14 +141,6 @@ export namespace IOMsg {
|
|
|
143
141
|
export let OVER_SIZE: number;
|
|
144
142
|
export let OVER_FLOW: number;
|
|
145
143
|
}
|
|
146
|
-
export type API_TYPE = {
|
|
147
|
-
REQUEST_RESPONSE: string;
|
|
148
|
-
ONE_WAY: string;
|
|
149
|
-
};
|
|
150
|
-
export namespace API_TYPE {
|
|
151
|
-
let REQUEST_RESPONSE: string;
|
|
152
|
-
let ONE_WAY: string;
|
|
153
|
-
}
|
|
154
144
|
export type STATUS = {
|
|
155
145
|
OK: number;
|
|
156
146
|
ERROR: number;
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { FileKeyProvider } from './src/auth/key_providers/FileKeyProvider.js'
|
|
|
20
20
|
export { RedisKeyProvider } from './src/auth/key_providers/RedisKeyProvider.js'
|
|
21
21
|
export { StringKeyProvider } from './src/auth/key_providers/StringKeyProvider.js'
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
export * as
|
|
25
|
-
export * as
|
|
26
|
-
export {
|
|
23
|
+
// services
|
|
24
|
+
export * as replyService from './src/services/replyService.js'
|
|
25
|
+
export * as sudoService from './src/services/sudoService.js'
|
|
26
|
+
export { RedisService } from './src/services/RedisService.js'
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ export class RedisKeyProvider {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
//sudoService call
|
|
24
24
|
async getAuthIdList() {
|
|
25
25
|
let result = await this.redis.keys(DEVICE_PREFIX + '*')
|
|
26
26
|
result = result.map(v => {
|
|
@@ -35,7 +35,7 @@ export class RedisKeyProvider {
|
|
|
35
35
|
return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
//sudoService call
|
|
39
39
|
async delAuth(id) {
|
|
40
40
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
41
41
|
}
|